std::basic_istream<CharT,Traits>::seekg (3) - Linux Manuals
std::basic_istream<CharT,Traits>::seekg: std::basic_istream<CharT,Traits>::seekg
NAME
std::basic_istream<CharT,Traits>::seekg - std::basic_istream<CharT,Traits>::seekg
Synopsis
basic_istream& seekg( pos_type pos );
basic_istream& seekg( off_type off, std::ios_base::seekdir dir);
Sets input position indicator of the current associated streambuf object. In case of failure, calls setstate(std::ios_base::failbit).
Before doing anything else, seekg clears eofbit. (since C++11)
seekg behaves as UnformattedInputFunction, except that gcount() is not affected. After constructing and checking the sentry object,
1) sets the input position indicator to absolute (relative to the beginning of the file) value pos. Specifically, executes rdbuf()->pubseekpos(pos, std::ios_base::in).
2) sets the input position indicator to position off, relative to position, defined by dir. Specifically, executes rdbuf()->pubseekoff(off, dir, std::ios_base::in).
Parameters
pos - absolute position to set the input position indicator to.
off - relative position to set the input position indicator to.
dir - beg the beginning of a stream
Return value
*this
Exceptions
failure if an error occurred (the error state flag is not goodbit) and exceptions() is set to throw for that state.
If an internal operation throws an exception, it is caught and badbit is set. If exceptions() is set for badbit, the exception is rethrown.
Example
// Run this code
Output:
See also
tellg (public member function)
tellp (public member function of std::basic_ostream<CharT,Traits>)
seekp (public member function of std::basic_ostream<CharT,Traits>)