Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
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
streambuf
streambuf::streambuf
streambuf::~streambuf
public members:
streambuf::getloc
streambuf::in_avail
streambuf::pubimbue
streambuf::pubseekoff
streambuf::pubseekpos
streambuf::pubsetbuf
streambuf::pubsync
streambuf::sbumpc
streambuf::sgetc
streambuf::sgetn
streambuf::snextc
streambuf::sputbackc
streambuf::sputc
streambuf::sputn
streambuf::sungetc
protected members:
streambuf::eback
streambuf::egptr
streambuf::epptr
streambuf::gbump
streambuf::gptr
streambuf::pbase
streambuf::pbump
streambuf::pptr
streambuf::setg
streambuf::setp
virtual prot. members:
streambuf::imbue
streambuf::overflow
streambuf::pbackfail
streambuf::seekoff
streambuf::seekpos
streambuf::setbuf
streambuf::showmanyc
streambuf::sync
streambuf::uflow
streambuf::underflow
streambuf::xsgetn
streambuf::xsputn


streambuf::pubseekoff

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

Set internal position pointer to relative position

Calls protected virtual member seekoff, which sets a new position value for one or both of the internal position pointers.

The parameter which determines which of the position pointers is affected: either the get pointer gptr or the put pointer pptr, or both.

Parameters

off
Offset value. This is relative to the way parameter.
It is a value of type streamoff, which can be implicitly constructed from an integral value.
way
Object of type ios_base::seekdir. It may take any of the following constant values:
valueoffset is relative to...
ios_base::begbeginning of the stream buffer
ios_base::curcurrent position in the stream buffer
ios_base::endend of the stream buffer
which
Determines which of the internal position pointers shall be modified: the input pointer, the output pointer, or both. It is an object of type ios_base::openmode that for this function may take any combination of the following significant constant values:
valueposition pointer affected
ios_base::inModify get pointer position
ios_base::outModify put pointer position

Return Value

The new position value of the modified position pointer.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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 it repositions the position pointer to the end of the file buffer.

Basic template member declaration

( basic_streambuf<charT,traits> )
1
2
3
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