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:
value | offset is relative to... |
ios_base::beg | beginning of the stream buffer |
ios_base::cur | current position in the stream buffer |
ios_base::end | end 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:
value | position pointer affected |
ios_base::in | Modify get pointer position |
ios_base::out | Modify 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
streambuf::seekoff | Set internal position pointer to relative position (virtual protected member function) |
|