Assertor
2006-02-26 06:25:35 UTC
Hi, All.
(VC++6.0)
I found some strange thins when using getline() and seekg() of
std::ifstream.
After the file position of an open file was shift to the end of the
file,
seekg() did not work rightly. (i.e. I could not move the file position
to the begin or some position using seekg())
see the following example code.
std::ifstream fStream("a.dat", std::ios::in);
fStream.seekg(3, std::ios::beg);
pos = fStream.tellg(); //<--- I checked if the postion is rigglty
moved and checked again by
getLine().
while( !fStream.eof() )
{
fStream.getline(bufff, MAX_LINE);
.....
}
fStream.seekg(3, std::ios::beg);
pos = fStream.tellg(); //<--- the position is move to the 3 from
the begin.
//in fact, the fstream's
postion pointed at the end of the file.
if( fStream.eof() )
std::cout<<"the end of this file\n"; <---- the string was printed.
:-(.
??
So. When the file position is shifted to the end of a file by using
getline(),
I CAN NOT move the file position????
(In this case, To go to the fist position of the file, I closed
the opened file then I reopened the file).
And for ur imformation,
In case of std::ofstream, seekp() was simlar to the above seekg() of
std::ifstream.
After the position was moved to end by getline(), though I move the
position by using seekp(), tellp() returned '-1'.
(VC++6.0)
I found some strange thins when using getline() and seekg() of
std::ifstream.
After the file position of an open file was shift to the end of the
file,
seekg() did not work rightly. (i.e. I could not move the file position
to the begin or some position using seekg())
see the following example code.
std::ifstream fStream("a.dat", std::ios::in);
fStream.seekg(3, std::ios::beg);
pos = fStream.tellg(); //<--- I checked if the postion is rigglty
moved and checked again by
getLine().
while( !fStream.eof() )
{
fStream.getline(bufff, MAX_LINE);
.....
}
fStream.seekg(3, std::ios::beg);
pos = fStream.tellg(); //<--- the position is move to the 3 from
the begin.
//in fact, the fstream's
postion pointed at the end of the file.
if( fStream.eof() )
std::cout<<"the end of this file\n"; <---- the string was printed.
:-(.
??
So. When the file position is shifted to the end of a file by using
getline(),
I CAN NOT move the file position????
(In this case, To go to the fist position of the file, I closed
the opened file then I reopened the file).
And for ur imformation,
In case of std::ofstream, seekp() was simlar to the above seekg() of
std::ifstream.
After the position was moved to end by getline(), though I move the
position by using seekp(), tellp() returned '-1'.