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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP