Input pattern and read text



 DEVELOP > c-Plus-Plus > Input pattern and read text

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "kittykat"
Date: 01 Dec 2004 12:30:41 PM
Object: Input pattern and read text
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?
.

User: "Dietmar Kuehl"

Title: Re: Input pattern and read text 01 Dec 2004 12:45:34 PM
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);
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting
.
User: "kittykat"

Title: Re: Input pattern and read text 01 Dec 2004 01:03:14 PM
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.
.
User: "Shailesh Humbad"

Title: Re: Input pattern and read text 01 Dec 2004 02:02:16 PM
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.
.
User: "kittykat"

Title: Re: Input pattern and read text 01 Dec 2004 02:24:27 PM
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!
.
User: "Shailesh Humbad"

Title: Re: Input pattern and read text 02 Dec 2004 01:18:58 AM
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.
.






  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER