Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:FormattedOutputFunction

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      Contents

      [edit]Requirements

      AFormattedOutputFunction is a member function ofstd::basic_ostream or a non-member function involvingstd::basic_ostream that performs the following operations:

      1. Constructs an objectsentry of typestd::basic_ostream::sentry.
      2. Ifbool(sentry) istrue, attempts to perform the desired output by inserting the characters into the output stream as if by callingrdbuf()->sputc(). Other public members ofstd::basic_ostream may also be used, but virtual members ofrdbuf() exceptoverflow(),xsputn() andsync() will never be called.
      3. Destroyssentry and returns*this.

      Ifsentry fails to be constructed, orbool(sentry) isfalse, no output takes place.

      If the output could not be generated, callssetstate(std::ios_base::failbit), which can throw an exception.

      If an exception is thrown during output, thenstd::ios_base::badbit is set in*this’s error state without causing astd::ios_base::failure to be thrown. If exceptions onbadbit are enabled in this stream'sexception mask (i.e.,(exceptions()& badbit)!=0), the exception is also rethrown.

      When an exception is thrown from the formatted output function,sentry is also destroyed before leaving the function.

      [edit]Padding

      Formatted output functions determine padding according tostd::num_put::do_put() stage 3.

      (until C++14)

      If a formatted output function of a streamos determines padding, it does so as follows.

      Given aCharT character sequenceseq whereCharT is thecharacter container type ofos, if the length ofseq is less thanos.width(), then enough copies ofos.fill() are added to this sequence as necessary to pad to a width ofos.width() characters.

      If(os.flags()&std::ios_base::adjustfield)==std::ios_base::left istrue, the fill characters are placed after the character sequence; otherwise, they are placed before the character sequence.

      (since C++14)

      [edit]Standard library

      The following standard library functions areFormattedOutputFunctions.

      (since C++17)
      except that (givenos is an output stream object):
      • any exception thrown by the call tostd::vformat is propagated without regard to the value ofos.exceptions() and without turning onios_base::badbit in the error state ofos;
      • if inserting intoos fails, callsos.setstate(ios_base::badbit) (which may throwios_base::failure).
      (since C++23)

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 160C++98the process of determining whether the exception caught
      is rethrown mentioned a non-existing functionexception()
      corrected toexceptions()
      LWG 165C++98the only virtual member allowed to be
      called onrdbuf() wasoverflow()
      also allowed
      xsputn() andsync()
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/FormattedOutputFunction&oldid=183230"

      [8]ページ先頭

      ©2009-2025 Movatter.jp