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