Well I just noticed that by changing the position -in microsoft visual studio- through "seekp" I implicitelly also change the read-position, when handling files.
I am wondering however if this is "portable" behaviour? Can I expect the position of reading & writing to be always the same? And consequently: will tellp
& tellg
always return the same value?
For file positions they are the same. In other words there is only one pointer maintained.
From
27.9.1.1p3
:So,
seekg
andseekp
are interchangeable for file streams. However, this is not true for other types of streams, as they may hold separate pointers for the put and get positions.Update: So from all the comments and everything, it seems that for fstream, seekp and seekg use the same pointer. But for stringstream and probably other non-file based streams, they are separate.
Original Post:
Doesn't work for me on linux with g++ 4.7.2. They seem to be independent:
Output:
Also the behaviour you describe sounds like it doesn't comply with the quotes here:
and here: