Basic_streambuf :: seekoff, which should be returned when ios_base :: in | is ios_base :: out specified?

27.6.3.4.2 Buffer management and positioning

pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out); 
  • Effects: changes the position of the stream within one or more controlled sequences in a manner that is defined separately for each class obtained from basic_streambuf in this clause (27.8.2.4, 27.9.1.5).
  • Default behavior: returns pos_type(off_type(-1)) .

So far so good. The basic_streambuf multiplier basic_streambuf can change its position separately for ios_base::in and / or ios_base::out . But what do I need to return when both parameters are specified?

If you specify ios_base::in or ios_base::out , we will return the new stream position of a specific sequence.

+8
c ++ iostream streambuf
source share
2 answers

It depends a little on your flow to determine what is going on. Embedded streams differ from each other in that some of them may have separate read and write positions (string stream), while others may have only one (fstream).

If the user is repositioning and indicating both, you might need to move both. If this is a zero-offset search in order to get the current position, it is impractical to fail if the positions are different.

+1
source share

Following the seekoff from 27.8.2.4, it seems like you should fail.

Check condition table 130, which indicates that both input and output sequences should only be located if

 (which & (ios_base::in | ios_base::out)) == (ios_base::in) | ios_base::out)) and way == either ios_base::beg or ios_base::end 
0
source share

All Articles