August 6th, 2003, 07:55 PM
Reading text in from a file in C++
Hey all, I've got what I hope is a simple question. I'm trying to read in a line of text from a file one character at a time. After I read the line of text in from the file I try to output the line one character at a time. This works fine, except that it apparently isn't reading in any spaces in the line of text. Here's the part of my code you'd probably be interested in.
ifstream INFILE("test.txt", ios::in);
cerr<<"Test.txt could not be opened"<<endl;
while (INFILE >> input)
cout<<"letter "<<x++<<": "<<input<<endl;
I really appreciate any help you guys could give me, I know it's kinda a newb. question. Thanks!
August 8th, 2003, 05:23 AM
Why dont you use INFILE.get() or INFILE.getline()
the code will be:
August 11th, 2003, 01:07 PM
Thanks, that worked great!