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: Alters the stream positions within one or more of the controlled sequences in a way that is defined separately for each class derived from
basic_streambuf
in this Clause (27.8.2.4, 27.9.1.5).- Default behavior: Returns
pos_type(off_type(-1))
.
到目前为止,还不错。我正在使用的 basic_streambuf
推导可以分别更改其在 ios_base::in
和/或 ios_base::out
中的位置。但是,当两者都指定时,我需要返回什么?
如果您指定ios_base::in
或 ios_base::out
,我们将返回特定序列的新流位置。
最佳答案
这有点取决于您的流来定义会发生什么。内置流的不同之处在于,有些可以有单独的读取和写入位置 (stringstream),而另一些只有一个 (fstream)。
如果用户重新定位并指定进出,也许您应该同时移动两者。如果是零偏移量寻找当前位置,位置不同则失败也不是没有道理的。
关于c++ - basic_streambuf::seekoff 当 ios_base::in | 应该返回什么? ios_base::out 被指定了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6800811/