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

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.


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


// 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);

  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.
  streambuf class

© The C++ Resources Network, 2001