| Defined in header <ios> | ||
|---|---|---|
template< class State > class fpos; |
Specializations of the class template std::fpos identify absolute positions in a stream or in a file. Each object of type fpos holds the byte position in the stream (typically as a private member of type std::streamoff) and the current shift state, a value of type State (typically std::mbstate_t).
The following specializations of std::fpos are provided:
| Type | Definition |
|---|---|
streampos | std::fpos<std::char_traits<char>::state_type> |
wstreampos | std::fpos<std::char_traits<wchar_t>::state_type> |
| In addition, | (since C++11) |
Member functions
| gets/sets the value of the shift state (public member function) |
In addition, the following member functions and operators must be provided, although it's unspecified if they are members or non-member.
- A constructor that accepts an argument of type
int. - A constructor that accepts an argument of type
std::streamoff. This constructor must also accept the special valuestd::streamoff(-1): thestd::fposconstructed in this manner is returned by some stream operations to indicate errors. - A conversion operator that converts
fpostostd::streamoffwith the value equal to the offset fromstd::fpos(0). -
operator==that compares two objects of typestd::fposand returns a value of type convertible tobool -
operator!=that compares two objects of typestd::fposand returns a value of type convertible tobool -
operator+andoperator+=which can addstd::streamofftostd::fpos -
operator-andoperator-=which can subtractstd::streamofffrom anstd::fpos -
operator-which can subtract two objects of typestd::fposproducing anstd::streamoff
Notes
std::streampos and std::wstreampos are required to be the same type because std::char_traits<char>::state_type and std::char_traits<wchar_t>::state_type are required to both be std::mbstate_t. C++98 had a self-contradictory statement that they may be different if the implementation supports no shift encoding in narrow-oriented iostreams but supports one or more shift encodings in wide-oriented streams, but that was corrected in C++03.
Some of the I/O streams member functions return and manipulate objects of member typedef pos_type. For streams, these member typedefs are provided by the template parameter Traits, which defaults to std::char_traits, which define their pos_types to be specializations of std::fpos. The behavior of the I/O streams library is implementation-defined when Traits::pos_type is not std::fpos<std::mbstate_t> (aka std::streampos or std::wstreampos).
See also
| represents relative file/stream position (offset from fpos), sufficient to represent any file size (typedef) | |
| returns the output position indicator (public member function of std::basic_ostream) | |
| sets the output position indicator (public member function of std::basic_ostream) | |
| gets the file position indicator (function) |
Please login to continue.