tellp() in file handling with C++

C++Server Side ProgrammingProgramming

In C++ file handling, the tellp() function is used with output streams, and returns the current put position of the pointer in the stream. It returns an integer data type, representing the current position of the stream pointer.

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

Algorithm

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.

Example

Live Demo

#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.
}

Output

The present position of the pointer in the file: 15
raja
Published on 02-Apr-2019 11:42:59
Advertisements