Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Input pattern and read text

Reply
Thread Tools

Input pattern and read text

 
 
kittykat
Guest
Posts: n/a
 
      12-01-2004
Hi again,
Ok, i've solved my own problem, but now i have a tiny problem that i can't
seem to solve. here's my code:
#include <fstream>
#include <string>
#include <iostream>

using namespace std;

int main()
{ string pattern;
ifstream myFile("data.txt");

cout << "Enter the item you are searching for: ";
cin >> pattern;

if (getline(myFile, pattern))
cout << "The pattern was found " << endl;
else
cout << "The pattern was not found in the list\n";

}

my code complied correctly. my problem is, when it runs, the window
appears and then disappears really quickly. i was wondering how i could
solve that?? is there something wrong with my code?



 
Reply With Quote
 
 
 
 
Dietmar Kuehl
Guest
Posts: n/a
 
      12-01-2004
kittykat wrote:
> Ok, i've solved my own problem,


Actually, I doubt that you did: the code you created does not search
for a pattern in any way!

> if (getline(myFile, pattern))


The above line just reads a line and stores it in the variable
'pattern', overwriting its contents. It does not care about the
contents prior to the statement.

> my code complied correctly. my problem is, when it runs, the window
> appears and then disappears really quickly.


Start your program from the command line! If you insist in starting
it from some IDE, you probably have to delay the termination of the
program, e.g. making the use hit return:

std::string dummy;
std::getline(std::cin, dummy);
--
<private.php?do=newpm&u=> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

 
Reply With Quote
 
 
 
 
kittykat
Guest
Posts: n/a
 
      12-01-2004
thanx for pointing that out. could you explain this bit please:
"Start your program from the command line! If you insist in starting it
from some IDE, you probably have to delay the termination of the program".


I dont understand what an IDE is.

 
Reply With Quote
 
Shailesh Humbad
Guest
Posts: n/a
 
      12-01-2004
kittykat wrote:
> thanx for pointing that out. could you explain this bit please:
> "Start your program from the command line! If you insist in starting it
> from some IDE, you probably have to delay the termination of the program".
>
>
> I dont understand what an IDE is.
>

IDE means integrated development environment. For example, Eclipse and
Visual Studio are IDEs. What's being integrated? The compiler, linker,
and various other tools that help you build your program. One thing the
IDE does is allow you to press a button to run your program instead of
manually running it from a command line by typing its name. In your
case, you probably want to do the latter so you can see all the output.
 
Reply With Quote
 
kittykat
Guest
Posts: n/a
 
      12-01-2004
I'm using Dev-C++, so how shall i run my program manually. what shall i
use? and what commands shall i use? i'm a beginner in C++, and have been
thrown in the deep end, so forgive me if my questions are really basic!

 
Reply With Quote
 
Shailesh Humbad
Guest
Posts: n/a
 
      12-02-2004
kittykat wrote:
> I'm using Dev-C++, so how shall i run my program manually. what shall i
> use? and what commands shall i use? i'm a beginner in C++, and have been
> thrown in the deep end, so forgive me if my questions are really basic!
>

Just go to start menu and click on "Run...". Then type in "cmd" or
"command". At the prompt, type "cd c:\my\program\directory". Then type
"myprogramname". You have to use your own directory name and program
name. Also, if you need further help, I suggest continuing this thread
by posting in the more topical alt.comp.lang.learn.c-c++. This
newsgroup is really only for C++ language-related discussion.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
Read input value from dynamic created input controls Melissa ASP .Net 2 12-26-2008 07:48 AM
documents related to factory design pattern and Abstract foctory pattern. sunny C++ 1 12-07-2006 04:26 AM
C++: Input pattern and find in text file kittykat C++ 3 12-09-2004 04:32 PM
why does form with only 1 text input and 1 button input submit on enter? Guy HTML 5 12-13-2003 06:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57