cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : streambuf : pubseekpos
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::pubseekpos public member function
streampos pubseekpos ( streampos sp, ios_base::openmode which = ios_base::in | ios_base::out );

Set internal position pointer to absolute position

Calls protected virtual member seekpos, 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

pos
New absolute position for the position pointer.
This is an object of class streampos (or traits::pos_type for other traits), which can be constructed directly from integral values representing a relative position from the beginning of the stream.
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::ininput position pointer
ios_base::outoutput position pointer

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 the 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 10th to 19th).

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

streambuf::pubseekoff Set internal position pointer to relative position (public member function)
streambuf::seekpos Set internal position pointer to absolute position (virtual protected member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us