1. C 2b 2b Ostream Dev Null Code
  2. C 2b 2b Ostream Dev Null Test
  3. C 2b 2b Ostream Dev Null Key
  4. C%2b%2b Ostream Dev Null
  5. C 2b 2b Ostream Dev Null Command

You can then use this buffer in any ostream class. NullBuffer nullbuffer; std::ostream nullstream(&nullbuffer); nullstream. Lo standard garantisce che questo 27.6.2.2 lib.ostream.cons p1, a partire da 27.6.2.2 lib.ostream.cons p1 che descrive il costruttore di ostream che accetta un puntatore a uno streambuf: Effetti: basicostream un object di class basicostream, assegnando i valori iniziali alla class base chiamando basicios::init(sb). An Ostream is an abstract base class for all output systems (streams, files, token lists.

这个问题已经在这里有了答案:
9年前关闭。

Possible Duplicate:
Implementing a no-op std::ostream


在c++中是否有与NULL等价的流?我想编写一个函数,如果用户希望将内部输出输出到某个地方,则将其带入一个流中,但是如果没有,则输出进入某个伪造的地方
我希望能够选择执行data()data(std::cout)

编辑:取自@Johannes Schaub-litb的邮件here,稍作修改:
使用这些:
现在,这看起来很酷,但是下面的代码更短并且更有效,因为如果将空指针提供给ostream的构造函数,它将自动设置Badbit并静默忽略任何写操作:
该标准从27.6.2.2 [lib.ostream.cons] p1开始,保证了它的工作,ostream描述了streambuf的构造函数,该构造函数采用指向basic_ios的指针:

Effects: Constructs an object of class basic_ostream, assigning initial values to the base class by calling basic_ios<charT,traits>::init(sb).


来自27.4.4.1 [lib.basic.ios.cons] p3badbit的相关功能:

void init(basic_streambuf<charT,traits>* sb);
Postconditions: The postconditions of this function are indicated in Table 89:


表89中的重要行:

rdstate() -- goodbit if sb is not a null pointer, otherwise badbit.


如果设置了27.6.2.6 [lib.ostream.unformatted],将在sentry下进行描述:

Each unformatted output function begins execution by constructing an object of class sentry. If this object returns true, while converting to a value of type bool, the function endeavors to generate the requested output.


这意味着,如果sentry为假,则不是。这是bool转换为27.6.2.3 [lib.ostream::sentry] p3 & p5的方式,取自ok_:

C 2b 2b Ostream Dev Null Code

3) If, after any preparation is completed, os.good() is true, ok_ true otherwise, ok_ false.

5) operator bool();
Effects: Returns ok_.


(ostream::sentrybool类型的27.6.2.2 [lib.ostream.cons] p1C%2b%2b的成员。)
请注意,这些引号在C++ 11中仍然存在,只是在不同的位置。为了在这个答案中出现:
  • 27.7.3.2 [ostream.cons] p1 =>27.4.4.1 [lib.basic.ios.cons] p3
  • 27.5.5.2 [basic.ios.cons] =>27.6.2.6 [lib.ostream.unformatted]
  • C 2b 2b ostream dev null test
  • 表89 =>表128
  • 27.7.3.7 [ostream.unformatted] p1 =>27.6.2.3 [lib.ostream::sentry] p3 & p5
  • 27.7.3.4 [ostream::sentry] p4 & p5 => ojit_code
  • 这个问题已经在这里有了答案:
    9年前关闭。

    Possible Duplicate:
    Implementing a no-op std::ostream


    在c++中是否有与NULL等价的流?我想编写一个函数,如果用户希望将内部输出输出到某个地方,则将其带入一个流中,但是如果没有,则输出进入某个伪造的地方
    我希望能够选择执行data()data(std::cout)

    编辑:取自@Johannes Schaub-litb的邮件here,稍作修改:
    使用这些:
    现在,这看起来很酷,但是下面的代码更短并且更有效,因为如果将空指针提供给ostream的构造函数,它将自动设置Badbit并静默忽略任何写操作:
    该标准从27.6.2.2 [lib.ostream.cons] p1开始,保证了它的工作,ostream描述了streambuf的构造函数,该构造函数采用指向basic_ios的指针:

    Effects: Constructs an object of class basic_ostream, assigning initial values to the base class by calling basic_ios<charT,traits>::init(sb).


    来自27.4.4.1 [lib.basic.ios.cons] p3badbit的相关功能:

    void init(basic_streambuf<charT,traits>* sb);
    Postconditions: The postconditions of this function are indicated in Table 89:


    表89中的重要行:

    rdstate() -- goodbit if sb is not a null pointer, otherwise badbit.


    如果设置了27.6.2.6 [lib.ostream.unformatted],将在sentry下进行描述:

    Each unformatted output function begins execution by constructing an object of class sentry. If this object returns true, while converting to a value of type bool, the function endeavors to generate the requested output.


    C 2b 2b Ostream Dev Null Test

    这意味着,如果sentry为假,则不是。这是C 2b 2b ostream dev null keybool转换为27.6.2.3 [lib.ostream::sentry] p3 & p5的方式,取自ok_:C%2b%2b ostream dev null

    3) If, after any preparation is completed, os.good() is true, ok_ true otherwise, ok_ false.

    5) operator bool();
    Effects: Returns ok_.


    (ostream::sentrybool

    C 2b 2b Ostream Dev Null Key

    类型的

    C%2b%2b Ostream Dev Null

    27.6.2.2 [lib.ostream.cons] p1的成员。)

    C 2b 2b Ostream Dev Null Command


    请注意,这些引号在C++ 11中仍然存在,只是在不同的位置。为了在这个答案中出现:
  • 27.7.3.2 [ostream.cons] p1 =>27.4.4.1 [lib.basic.ios.cons] p3
  • 27.5.5.2 [basic.ios.cons] =>27.6.2.6 [lib.ostream.unformatted]
  • 表89 =>表128
  • 27.7.3.7 [ostream.unformatted] p1 =>27.6.2.3 [lib.ostream::sentry] p3 & p5
  • 27.7.3.4 [ostream::sentry] p4 & p5 => ojit_code