-
November 17th, 2008, 09:41 PM
#1
getline
while ( getline ( infile, buffer ) ) {
// Process the line
}
I'm reading a file from the stream to display in the console, but it only displays the first line how do I display the other lines?
-
November 17th, 2008, 10:21 PM
#2
Re: getline
You should be able to check for eof.
Code:
while (!infile.eof())
{
//read line from infile and process.
}
Last edited by ahoodin; November 17th, 2008 at 10:42 PM.
ahoodin
To keep the plot moving, that's why.
-
November 17th, 2008, 10:43 PM
#3
Re: getline
changed my post. Have a look.
ahoodin
To keep the plot moving, that's why.
-
November 18th, 2008, 06:56 AM
#4
Re: getline
1) the original code is correct. Supply a short program and a sample
input file showing the error
2) It is almost always an error in logic to put the eof() check as shown
in the second post (as you need to check for eof() inside the loop
also when reading in that way.
Remember eof() is only true after ATTEMPTING to read past EOF.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|