目录

tellp

描述 (Description)

它用于获取输出序列中的位置,并返回输出流中当前字符的位置。

声明 (Declaration)

以下是std :: ostream :: tellp的声明。

streampos tellp();

参数 (Parameters)

没有

返回值 (Return Value)

它返回流中的当前位置。 如果与流关联的流缓冲区不支持该操作,或者如果它失败,则该函数返回-1。

异常 (Exceptions)

Basic guarantee - 如果抛出异常,则对象处于有效状态。

数据竞争 (Data races)

它修改了流对象。

例子 (Example)

在下面的例子中解释了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;
}
↑回到顶部↑
WIKI教程 @2018