Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

istream: seekg / tellg, peculiar behaviour

Status
Not open for further replies.

LiquidEyes

Programmer
Sep 13, 2004
2
GB
I'm having two istream-related problems. Please can somebody help... [ponder]

Problem 1

void loadStuffFromStream (istream& stream)
{
// goes too far!!
stream.seekg( length, ios_base::cur );
}

This always skips (length*2) bytes instead of length. Why does it do this? I thought istream was specialised on chars not w_chars?

Problem 2

char ch;
int pos;
...
pos = stream.tellg(); // now pos=0
stream.get (ch);
pos = stream.tellg(); // now pos=3585 ???
stream.get (ch);
pos = stream.tellg(); // now pos=3586
stream.get (ch);
pos = stream.tellg(); // now pos=3587
stream.get (ch);
// etc...

Not so much a 'problem' as a matter of curiosity. Why is there a sudden leap in the read-position reported by tellg the first time I read from the stream? (N.B. It is reading the correct characters into ch!)
 
P.S. On further examination, I think the (length*2) thing was a coincidence. Unless length==0, seekg just seems to seek to an arbitrary position in the stream.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top