streambuf::pubseekpos
streampos pubseekpos ( streampos sp, ios_base::openmode which = ios_base::in | ios_base::out );
streambuf
  cplusplus.com  

Set position of internal position pointer.
  Calls protected virtual member seekpos.
  The standard behavior of function seekpos in derived stream buffer classes is to set a new position value for an internal position pointer. Often, strembuf derived object have independent input and output position pointers, which parameter determines which one is affected.

Parameters.

pos
New position for the position pointer.
This is an object of class streampos. streampos objects may be constructed from streamoff integer values representing a relative position from the beginning of the stream.
which
Determines which of the internal position pointers shall be modified, either in, out or both. It is an object of type ios_base::openmode that may take any combination of the following significant constant values:

Return Value.
  The new position value of the modified position pointer.

Example.

// changing position with pubseekpos
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  int n;
  buffer;
  filebuf* pbuf;
  char buffer[11];

  fstream filestr ("test.txt");
  pbuf = filestr.rdbuf();

  // change position to 10th character
  pbuf->pubseekpos(10);
  // read 10 characters
  pbuf->sgetn (buffer,10);
  // append null character to string
  buffer[10]=0;

  filestr.close();

  cout << buffer << endl;

  return 0;
}
This example reads and prints 10 characters of a file starting at position 10 (characters 10 to 19)

Basic template member declaration ( basic_streambuf<charT,traits> ):
typedef traits::pos_type pos_type;
pos_type pubseekpos (pos_type sp, ios_base which = ios_base::in | ios_base::out );

See also.
  pubseekoff
  streambuf class


© The C++ Resources Network, 2001