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+ 次瀏覽

開啟你的職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.