C++ Ostream Library - tellp



Description

It is used to get position in output sequence and returns the position of the current character in the output stream.

Declaration

Following is the declaration for std::ostream::tellp.

streampos tellp();

Parameters

none

Return Value

It returns the current position in the stream. If either the stream buffer associated to the stream does not support the operation, or if it fails, the function returns -1.

Exceptions

Basic guarantee − if an exception is thrown, the object is in a valid state.

Data races

It modifies the stream object.

Example

In below example explains about std::ostream::tellp.

#include <fstream>

int main () {

   std::ofstream outfile;
   outfile.open ("test.txt");

   outfile.write ("This is an apple",16);
   long pos = outfile.tellp();
   outfile.seekp (pos-7);
   outfile.write (" sam",4);

   outfile.close();

   return 0;
}
ostream.htm
Advertisements