Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::fpos

      From cppreference.com
      <cpp‎ |io
       
       
       
      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::streamposstd::fpos<std::char_traits<char>::state_type>
      std::wstreamposstd::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

      [edit]Template parameter

      State - the type representing the shift state
      Type requirements
      -
      State must meet the requirements ofDestructible,CopyAssignable,CopyConstructible andDefaultConstructible.

      [edit]Member functions

      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:

      • A default constructor that stores an offset of zero and value-initializes the state object.
      • A non-explicit constructor that accepts an argument of type (possibly const)std::streamoff, which stores that offset and value-initializes the state object. This constructor must also accept the special valuestd::streamoff(-1): thestd::fpos constructed in this manner is returned by some stream operations to indicate errors.
      • Explicit conversion from (possibly const)fpos tostd::streamoff. The result is the stored offset.
      • operator== andoperator!= that compare two objects of type (possibly const)std::fpos and return abool prvalue.p!= q is equivalent to!(p== q).
      • operator+ andoperator- such that, for an objectp of type (possibly const)fpos<State> and an objecto of type (possibly const)std::streamoff
      • p+ o has typefpos<State> and stores an offset that is the result of addingo to the offset ofp.
      • o+ p has a type convertible tofpos<State> and the result of the conversion is equal top+ o.
      • p- o has typefpos<State> and stores an offset that is the result of subtractingo from the offset ofp.
      • operator+= andoperator-= which can accept a (possibly const)std::streamoff and adds/subtracts it from the stored offset, respectively.
      • operator- which can subtract two objects of type (possibly const)std::fpos producing anstd::streamoff, such that for two such objectsp andq,p== q+(p- q).

      [edit]Notes

      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_types 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.).

      [edit] Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 57C++98streampos andwstreampos were contradictionally
      allowed to be different while required to be the same
      clarified to
      be the same
      P0759R1C++98specification was unclear and incompletecleaned up
      P1148R0C++11unclear what and in which header the
      definitionsu16streampos andu32streampos are
      made clear
      LWG 2114
      (P2167R3)
      C++98non-bool return types of equality comparisons were alloweddisallowed

      [edit]See also

      represents relative file/stream position (offset from fpos), sufficient to represent any file size
      (typedef)[edit]
      returns the output position indicator
      (public member function ofstd::basic_ostream<CharT,Traits>)[edit]
      sets the output position indicator
      (public member function ofstd::basic_ostream<CharT,Traits>)[edit]
      gets the file position indicator
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/fpos&oldid=175940"

      [8]ページ先頭

      ©2009-2025 Movatter.jp