Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

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