0

Im using ifstream to read the content in text file.
But i want to ignore the first 5 line content.

what i do now is using the own function to ignore 1st 5 line content, then save it into new file and reopen the file again.
i think this is very waste time and also memory..any suggestion?
Thank you!

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by mvmalderen
0

Why not
- read 5 lines
- do what you were going to do anyway

It doesn't need a temp file to do that.

0

oh,can use this method also.thx.
another question now...

how to reload the content inside the ifstream file. Below is a part of code i doing now..

ifstream infile("test.txt");
string line2;
while (!infile.eof())
	{
		getline(infile,line2);
		itotalCount++;
	}

Here is ok.i get the total line in that file.
But next when i need find another info in that file,
the while loop din't function.i think is because the previous line is already reach the eof..

while (!infile.eof())
{
   getline(infile,line2);

}

and i have try to use the infile.seekg(0);
but the content return from getline function is nothing.zz


So, have any ideal can reload the content? Or there is already got function in stl which i dunno?
I'm waiting your answer..Thank you!

0

Don't use EOF as an exit indicator for your loop, instead read a file like this:

while ( getline(infile, line2) )
{
   // Do stuff with the read data
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.