I/O manipulators | ||||
Print functions(C++23) | ||||
C-style I/O | ||||
Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
fpos | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Defined in header <ios> | ||
template<class State> class fpos; | ||
Specializations of the class templatestd::fpos
identify absolute positions in a stream or in a file. Each object of typefpos
holds the byte position in the stream (typically as a private member of typestd::streamoff) and the current shift state, a value of typeState
(typicallystd::mbstate_t).
The following typedef names forstd::fpos<std::mbstate_t> are provided (although they are spelled differently in the standard, they denote the same type):
Defined in header <iosfwd> | |
Type | Definition |
std::streampos | std::fpos<std::char_traits<char>::state_type> |
std::wstreampos | std::fpos<std::char_traits<wchar_t>::state_type> |
std::u8streampos (C++20) | std::fpos<std::char_traits<char8_t>::state_type> |
std::u16streampos (C++11) | std::fpos<std::char_traits<char16_t>::state_type> |
std::u32streampos (C++11) | std::fpos<std::char_traits<char32_t>::state_type> |
All specializations offpos
meet theDefaultConstructible,CopyConstructible,CopyAssignable,Destructible, andEqualityComparable requirements.
IfState
is trivially copy constructible,fpos
has a trivial copy constructor. IfState
is trivially copy assignable,fpos
has a trivial copy assignment operator. IfState
is trivially destructible,fpos
has a trivial destructor.
Contents |
State | - | the type representing the shift state |
Type requirements | ||
-State must meet the requirements ofDestructible,CopyAssignable,CopyConstructible andDefaultConstructible. |
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::fpos
constructed in this manner is returned by some stream operations to indicate errors.fpos
tostd::streamoff. The result is the stored offset.std::fpos
and return abool prvalue.p!= q is equivalent to!(p== q).fpos<State>
and an objecto of type (possibly const)std::streamofffpos<State>
and stores an offset that is the result of addingo to the offset ofp.fpos<State>
and the result of the conversion is equal top+ o.fpos<State>
and stores an offset that is the result of subtractingo from the offset ofp.std::fpos
producing anstd::streamoff, such that for two such objectsp andq,p== q+(p- q).Some of theI/O streams member functions return and manipulate objects of member typedefpos_type
. For streams, these member typedefs are provided by the template parameterTraits
, which defaults tostd::char_traits, which define theirpos_type
s to be specializations ofstd::fpos
. The behavior of the I/O streams library is implementation-defined whenTraits::pos_type
is notstd::fpos<std::mbstate_t> (akastd::streampos
,std::wstreampos
, etc.).
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 57 | C++98 | streampos andwstreampos were contradictionallyallowed to be different while required to be the same | clarified to be the same |
P0759R1 | C++98 | specification was unclear and incomplete | cleaned up |
P1148R0 | C++11 | unclear what and in which header the definitions u16streampos andu32streampos are | made clear |
LWG 2114 (P2167R3) | C++98 | non-bool return types of equality comparisons were allowed | disallowed |
represents relative file/stream position (offset from fpos), sufficient to represent any file size (typedef)[edit] | |
returns the output position indicator (public member function of std::basic_ostream<CharT,Traits> )[edit] | |
sets the output position indicator (public member function of std::basic_ostream<CharT,Traits> )[edit] | |
gets the file position indicator (function)[edit] |