streambuf::pubseekoff
streampos pubseekoff ( streamoff off, ios_base::seekdir way, ios_base::openmode which = ios_base::in | ios_base::out );
streambuf
  cplusplus.com  

Set position of internal position pointer.
  Calls protected virtual member seekoff.
  The standard behavior of function seekoff 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.

off
Offset value. This is relative to way parameter.
It is an integer value, an object of type streamoff.
way
It is an object of type ios_base::seekdir. It may take any of the following constant values:
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.

// get file size using pubseekoff
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  long size;
  filebuf* pbuf;

  fstream filestr ("test.txt");
  pbuf = filestr.rdbuf();
  size = pbuf->pubseekoff(0,ios_base::end);
  filestr.close();

  cout << "size of file is " << size << endl;

  return 0;
}
This program prints out the size of file test.txt using the value returned by pubseekoff when repositioning to the end.

Basic template member declaration ( basic_streambuf<charT,traits> ):
typedef traits::pos_type pos_type;
typedef traits::off_type off_type;
pos_type pubseekoff (off_type off, ios_base::seekdir way, ios_base which = ios_base::in | ios_base::out );

See also.
  pubseekpos
  streambuf class


© The C++ Resources Network, 2001