c++ - basic_streambuf::seekoff 当 ios_base::in | 应该返回什么? ios_base::out 被指定了吗?

标签 c++ iostream streambuf

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/

相关文章:

c++ - 如何从.bat文件设置MSVC “Native Tools Command Prompt”?

c++ - 关于重新定义成员函数的小问题

c++ - 实现定义的文件流同步——为什么?

c++ - 如何为自定义 istream/streambuf 实现 seekg()?

c++ - std::streambuf::in_aval 总是为 std::ostream 返回 0

c++ - 如何释放共享指针的内存?

c++ - 帮助修复内存泄漏

c++11 - 为什么 reference_wrapper 对于内置类型的行为不同?

c++ - 将 fstream ">>"作为函数参数传递

c++ - C++ 标准是否要求 iostreams 性能不佳,或者我只是在处理一个糟糕的实现?