ostream::seekp
ostream&  seekp ( streampos pos );
ostream&  seekp ( streamoff off, ios_base::seekdir dir );
ostream
  cplusplus.com  

Set position of the put pointer.
  Sets the position of the put pointer. The put pointer determines the next location where to write in the buffer associated to the output stream.  

Parameters.

pos
The new position in the stream buffer. This parameter is an object of type streampos
off
Value of type streamoff indicating the offset in the stream's buffer. It is relative to dir parameter.
dir
Seeking direction. An object of type seekdir that may take any of the following values:

Return Value.
  The function returns *this

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 seekp is used to move the put pointer back to a position 7 characters before the end of the first output operation. 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;
typedef traits::off_type off_type;
basic_ostream& seekp ( pos_type pos );
basic_ostream& seekp ( off_type off, ios_base::seekdir dir );

See also.
  tellp, istream::seekg, istream::tellg
  ostream class


© The C++ Resources Network, 2001