cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : ostream : tellp
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
ostream
· ostream::ostream
· ostream::~ostream
member classes:
· ostream::sentry
member functions:
· ostream::flush
· ostream::operator<<
· ostream::put
· ostream::seekp
· ostream::tellp
· ostream::write

-

ostream::tellp public member function
streampos tellp ( );

Get position of put pointer

Returns the absolute position of the put pointer.

The put pointer determines the location in the output sequence where the next output operation is going to take place.

Parameters

none

Return Value

An integral value of type streampos with the number of characters between the beginning of the output sequence and the current position.

Failure is indicated by returning a value of -1.

Example

// position of put pointer
#include <fstream>
using namespace std;

int main () {
  long pos;

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

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

  outfile.close();

  return 0;
}

In this example, tellp is used to get the position of the put pointer after the writing operation. The pointer is then moved back 7 characters to modify the file at that position, so the final content of the file shall be:
This is a sample

Basic template member declaration

(basic_ostream<charT,traits>)
typedef traits::pos_type pos_type;
pos_type tellp ();

See also

istream::seekg Set position of the get pointer (public member function)
ostream::tellp Get position of put pointer (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us