are “seekp” & “seekg” interchangeable?

后端 未结 2 803
忘了有多久
忘了有多久 2020-12-05 23:50

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

2条回答
  •  天涯浪人
    2020-12-06 00:32

    For file positions they are the same. In other words there is only one pointer maintained.

    From 27.9.1.1p3:

    A joint file position is maintained for both the input sequence and the output sequence.

    So, seekg and seekp 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.

提交回复
热议问题