problem with getline

B

bg

hi all,

i need to parse a text file, making several passes over it. I'm doing
something like this:

ifstream input(args[2]);
......
string line;
while(getline(input,string)) // first pass works ok
{
...
}
// reset fpos to beginning of input and parse again
input.seekg(0,ios::beg);
while(getline(input,string)) // second pass - never enters
{
...
}

the problem i'm seeing is that the second while is never entered,
presumaby because i'm not resetting the file back to the begining
correclty?

whats the correct way?
TIA

i'm using xcode 1.2/gcc 3.3?

bg
 
D

David Harmon

On 26 Jun 2004 15:09:45 -0700 in comp.lang.c++, (e-mail address removed) (bg)
wrote,
while(getline(input,string)) // first pass works ok
{
...
}
// reset fpos to beginning of input and parse again

When the getline fails (or any input fails) the stream is set to the
fail state. It will do nothing for you until you call input.clear().

This issue is vaguely related to topic "[15.3] How can I get std::cin to
skip invalid input characters?" in Marshall Cline's C++ FAQ. It is
always good to check the FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top