在C ++文件处理中,该tellp()
函数与输出流一起使用,并返回指针在流中的当前放置位置。它返回一个整数数据类型,表示流指针的当前位置。
tellp()方法不接受参数。 它写为:pos_type tellp();
Begin. 针对类fstream创建一个对象newfile。 调用open()方法打开文件“点.txt“使用对象newfile执行写操作。 将数据插入文件对象newfile。 调用tellp()方法以打印指针在file对象中的当前位置。 调用close()方法关闭file对象。 End.
#include <iostream> #include <iostream> #include <fstream> using namespace std; int main() { fstream newfile; newfile.open("tpoint.txt", ios::out); //打开文件以使用文件对象执行写操作 newfile << "nhooo.com"; //插入数据 cout << "指针在文件中的当前位置: " << newfile.tellp() << endl; //指针在文件对象中的位置 newfile.close(); //关闭文件对象。 }
输出结果
指针在文件中的当前位置: 15