C++ Ostream 库 - tellp
描述
它用于获取输出序列中的位置并返回当前字符在输出流中的位置。
声明
以下是 std::ostream::tellp 的声明。
streampos tellp();
参数
none
返回值
它返回流中的当前位置。 如果与流关联的流缓冲区不支持该操作,或者如果它失败,则该函数返回 -1。
异常
Basic guarantee − 如果抛出异常,则对象处于有效状态。
数据竞争
它修改流对象。
示例
在下面的例子中解释了 std::ostream::tellp。
#include <fstream>
int main () {
std::ofstream outfile;
outfile.open ("test.txt");
outfile.write ("This is an apple",16);
long pos = outfile.tellp();
outfile.seekp (pos-7);
outfile.write (" sam",4);
outfile.close();
return 0;
}

