468,504 Members | 1,946 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

ifstream in text mode + seekg problem

Hi,

// Under C++Builder 2007 (+ Dinkumware)
#include <fstream>
using namespace std;

int main (int argc, char* argv[])
{
// Create a DOS-Text file, that has only two lines:
// - the first line is empty ("\r\n"),
// - the second line: "ABC".
// Then:

ifstream is ("c:\\abc.txt");

while (is.peek() != 'A') // It's a dead loop here... Why?
is.seekg (1, ios::cur);

return 0;
}

Thanks,
Vadim
Jan 18 '08 #1
1 4214
Vadim Volevach wrote:
// Under C++Builder 2007 (+ Dinkumware)
#include <fstream>
using namespace std;
int main (int argc, char* argv[])
{
// Create a DOS-Text file, that has only two lines:
// - the first line is empty ("\r\n"),
// - the second line: "ABC".
// Then:
ifstream is ("c:\\abc.txt");
while (is.peek() != 'A') // It's a dead loop here... Why?
is.seekg (1, ios::cur);
return 0;
}
It's undefined behavior. The only seeking you can do in a text
file is to the start of the file, to the current position, or to
a streampos returned from a call to tell[gp]().

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 18 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Hamburgpear | last post: by
2 posts views Thread by Karl | last post: by
5 posts views Thread by Kamran | last post: by
3 posts views Thread by toton | last post: by
4 posts views Thread by supemoy | last post: by
1 post views Thread by Sergei Shelukhin | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.