C++ 文件操作中的 tellp() 函数


在 C++ 文件操作中,tellp() 函数用于输出流,并返回流中指针的当前写入位置。它返回一个整型数据类型,代表流指针的当前位置。

tellp() method takes no parameter.
It is written as: pos_type tellp();

算法

Begin.
   Create an object newfile against the class fstream.
   Call open() method to open a file “tpoint.txt” to perform write operation using object newfile.
   Insert data into the file object newfile.
   Call the tellp() method to print the present position of the pointer in the file object.
   Call close() method to close the file object.
End.

实例

在线演示

#include <iostream>
#include <iostream>
#include <fstream>
using namespace std;
int main() {
   fstream newfile;
   newfile.open("tpoint.txt", ios::out); //open a file to perform write operation using file object
   newfile << "Tutorials Point"; //inserting data
   cout << "The present position of the pointer in the file: "
   << newfile.tellp() << endl; //position of the pointer in the file object
   newfile.close(); //close file object.
}

输出

The present position of the pointer in the file: 15

更新时间:2019 年 7 月 30 日

1,000+ 次浏览

开启你的职业生涯

完成课程即可获得认证

开始学习
广告