T
toton
Hi,
I want to unread a few things while I am reading a file. One
solution I know is putback the characters read to the buffer.
But as I need frequent moving file pointer , to a few steps back, I
was thinking of seekg & tellg function. But it is not workings as I
expect....
here is the test code,
std::string word;
std::string value;
while(stream_){
std::ifstream:os_type pos = stream_.tellg();///Mark the current
stream pos (2933)
stream_ >> word; ///read the word
std::ifstream:os_type pos1 = stream_.tellg();///stream pos (2942)
good
if(word == ".PEN_DOWN"){
int y;
stream_>>y; /// read some int from stream (the next one was int here
209, thus successful).
stream_.seekg(pos); ///seek to previous pos i.e 2933
std::ifstream:os_type pos2 = stream_.tellg();///once again
check the current pos. Yes it is 2933
std::string x;
stream_>>x;///now read the string I expect it to be .PEN_DOWN
again. but it is 198
}
The content of the file at that portion is,
..SEGMENT WORD 0-5 OK "Zaadje"
..PEN_DOWN
209 1810
198 1812
198 1812
198 1813
Is this a problem with internal buffering or operator>> ? How can
otherwise I go to the previously marked position ?
abir
I want to unread a few things while I am reading a file. One
solution I know is putback the characters read to the buffer.
But as I need frequent moving file pointer , to a few steps back, I
was thinking of seekg & tellg function. But it is not workings as I
expect....
here is the test code,
std::string word;
std::string value;
while(stream_){
std::ifstream:os_type pos = stream_.tellg();///Mark the current
stream pos (2933)
stream_ >> word; ///read the word
std::ifstream:os_type pos1 = stream_.tellg();///stream pos (2942)
good
if(word == ".PEN_DOWN"){
int y;
stream_>>y; /// read some int from stream (the next one was int here
209, thus successful).
stream_.seekg(pos); ///seek to previous pos i.e 2933
std::ifstream:os_type pos2 = stream_.tellg();///once again
check the current pos. Yes it is 2933
std::string x;
stream_>>x;///now read the string I expect it to be .PEN_DOWN
again. but it is 198
}
The content of the file at that portion is,
..SEGMENT WORD 0-5 OK "Zaadje"
..PEN_DOWN
209 1810
198 1812
198 1812
198 1813
Is this a problem with internal buffering or operator>> ? How can
otherwise I go to the previously marked position ?
abir