| Defined in header |
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
The following specializations of
std::fpos are provided:
State is trivially copy constructible,
fpos has a trivial copy constructor. If
State is trivially copy assignable,
fpos has a trivial copy assignment operator. If
State is trivially destructible,
fpos has a trivial destructor.
|State||-||the type representing the shift state|
| gets/sets the value of the shift state
(public member function)
In addition, member and non-member functions are provided to support the following operations:
std::streamoff, which stores that offset and and value-initializes the state object. This constructor must also accept the special value
std::fposconstructed in this manner is returned by some stream operations to indicate errors.
std::streamoff. The result is the stored offset.
operator!=that compare two objects of type (possibly const)
std::fposand returns a value of type convertible to
p != qis equivalent to
!(p == q).
operator-such that, for an object
pof type (possibly const)
fpos<State>and an object
oof type (possibly const)
p + ohas type
fpos<State>and stores an offset that is the result of adding
oto the offset of
o + phas a type convertible to
fpos<State>and the result of the conversion is equal to
p + o
p - ohas type
fpos<State>and stores an offset that is the result of subtracting
ofrom the offset of
operator-=which can accept a (possibly const)
std::streamoffand adds/subtracts it from the stored offset, respectively.
operator-which can subtract two objects of type (possibly const)
std::streamoff, such that for two such objects
p == q + (p - q)
std::wstreampos are required to be the same type because
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
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
|DR||Applied to||Behavior as published||Correct behavior|
|P0759R1||C++98||specification was unclear and incomplete||cleaned up|
| represents relative file/stream position (offset from fpos), sufficient to represent any file size
| returns the output position indicator
(public member function of
| sets the output position indicator
(public member function of
| gets the file position indicator
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.