C++ Ostream 库 - seekp
描述
它用于设置输出序列中的位置。
声明
以下是 std::ostream::seekp 的声明。
(1) ostream& seekp (streampos pos); (2) ostream& seekp (streamoff off, ios_base::seekdir way);
参数
pos − 它用于在流中查找绝对位置。
off − 偏移值,相对于方式参数。
返回值
它返回 ostream 对象 (*this)。
异常
Basic guarantee − 如果抛出异常,则对象处于有效状态。
数据竞争
Modifies the stream object and 对同一流对象的并发访问可能会导致数据竞争。
示例
在下面的例子中解释了 std::ostream::seekp。
#include <fstream>
int main () {
std::ofstream outfile;
outfile.open ("tutorialspoint.txt");
outfile.write ("This is an apple",16);
long pos = outfile.tellp();
outfile.seekp (pos-7);
outfile.write (" sai",4);
outfile.close();
return 0;
}

