- C 2b 2b Ostream Dev Null Command
- C 2b 2b Ostream Dev Null Key
- C%2b%2b Ostream Dev Null
- C 2b 2b Ostream Dev Null Test
- C 2b 2b Ostream Dev Null Code
这个问题已经在这里有了答案: 9年前关闭。 Possible Duplicate: Implementing a no-op std::ostream 在c中是否有与NULL等价的流?我想编写一个函数,如果用户希望将内部输出输出到某个地方,则将其带入一个流中,但是如果没有,则输出进入某个伪造的地方.
C++Language | ||||
Standard Library Headers | ||||
Freestanding and hosted implementations | ||||
Named requirements | ||||
Language support library | ||||
Concepts library(C++20) | ||||
Diagnostics library | ||||
Utilities library | ||||
Strings library | ||||
Containers library | ||||
Iterators library | ||||
Ranges library(C++20) | ||||
Algorithms library | ||||
Numerics library | ||||
Localizations library | ||||
Input/output library | ||||
Filesystem library(C++17) | ||||
Regular expressions library(C++11) | ||||
Atomic operations library(C++11) | ||||
Thread support library(C++11) | ||||
Technical Specifications |
971 // with rawnullostream, but it's better to have rawnullostream follow 972 // the rules than to change the rules just for rawnullostream. 我有一个C应用程序,其中包含大量的std::cout。它运行在linux 2.6.x上。 它运行在linux 2.6.x上。 我需要测试应用程序的性能,因此我正在考虑将 std::cout 重定向到 /dev/null 。.
- 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).
- They are two different code std::ostream/code objects that map to two different file descriptors of the OS (namely: 1 and 2). By default they both map to the console output, but they can be redirected in different devices or files.
I/O manipulators | ||||
C-style I/O | ||||
Buffers | ||||
(deprecated in C++98) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(deprecated in C++98) | ||||
(deprecated in C++98) | ||||
(deprecated in C++98) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Global objects | ||||
Member functions | ||||
(C++11) | ||||
Formatted output | ||||
Unformatted output | ||||
Positioning | ||||
Miscellaneous | ||||
(C++11) | ||||
Member classes | ||||
Non-member functions |
basic_ostream& operator<<(short value ); basic_ostream& operator<<(unsignedshort value ); | (1) | |
basic_ostream& operator<<(int value ); basic_ostream& operator<<(unsignedint value ); | (2) | |
basic_ostream& operator<<(long value ); basic_ostream& operator<<(unsignedlong value ); | (3) | |
basic_ostream& operator<<(longlong value ); basic_ostream& operator<<(unsignedlonglong value ); | (4) | (since C++11) |
basic_ostream& operator<<(float value ); basic_ostream& operator<<(double value ); | (5) | |
(6) | ||
basic_ostream& operator<<(constvoid* value ); | (7) | |
(8) | (since C++17) | |
basic_ostream& operator<<(std::basic_streambuf<CharT, Traits>* sb); | (9) | |
basic_ostream& operator<<( std::ios_base&(*func)(std::ios_base&)); | (10) | |
basic_ostream& operator<<( std::basic_ios<CharT,Traits>&(*func)(std::basic_ios<CharT,Traits>&)); | (11) | |
basic_ostream& operator<<( std::basic_ostream<CharT,Traits>&(*func)(std::basic_ostream<CharT,Traits>&)); | (12) |
Inserts data into the stream.
value
is short or int, then casts it to unsignedshort or unsignedint if ios_base::flags()& ios_base::basefield is ios_base::oct or ios_base::hex. After that, casts to long in any case and outputs as in (3). If value
is unsignedshort or unsignedint, casts to unsignedlong and outputs as in (3).C 2b 2b Ostream Dev Null Command
*this << s
, where s
is a null-terminated character type string.sb
is a null pointer. If it is, executes setstate(badbit) and exits. Otherwise, extracts characters from the input sequence controlled by sb
and inserts them into *this until one of the following conditions are met:- end-of-file occurs on the input sequence;
- inserting in the output sequence fails (in which case the character to be inserted is not extracted);
- an exception occurs (in which case the exception is caught).
failbit
is set in exceptions(), rethrows the exception.[edit]Parameters
value | - | integer, floating-point, boolean, or pointer value to insert |
func | - | function to call |
sb | - | pointer to the streambuffer to read the data from |
[edit]Return value
[edit]Notes
There are no overload for pointers to non-static member, pointers to volatile, or function pointers (other than the ones with signatures accepted by the (10-12) overloads). Attempting to output such objects invokes implicit conversion to bool, and, for any non-null pointer value, the value 1 is printed (unless boolalpha was set, in which case true is printed).
Character and character string arguments (e.g., of type char or constchar*) are handled by the non-member overloads of operator<<
. Attempting to output a character using the member function call syntax (e.g., std::cout.operator<<('c');) will call one of overloads (2-4) and output the numerical value. Attempting to output a character string using the member function call syntax will call overload (7) and print the pointer value instead.
[edit]Example
Output:
[edit]See also
inserts character data (function template)[edit] | |
performs stream I/O of strings (function template) | |
performs stream input and output of bitsets (function) | |
serializes and deserializes a complex number (function template) | |
performs stream input and output on pseudo-random number engine (function template)[edit] | |
performs stream input and output on pseudo-random number distribution (function template)[edit] | |
inserts a character (public member function)[edit] | |
inserts blocks of characters (public member function)[edit] | |
(C++17) | converts an integer or floating-point value to a character sequence (function)[edit] |
Language | ||||
Standard Library Headers | ||||
Freestanding and hosted implementations | ||||
Named requirements | ||||
Language support library | ||||
Concepts library(C++20) | ||||
Diagnostics library | ||||
Utilities library | ||||
Strings library | ||||
Containers library | ||||
Iterators library | ||||
Ranges library(C++20) | ||||
Algorithms library | ||||
Numerics library | ||||
Localizations library | ||||
Input/output library | ||||
Filesystem library(C++17) | ||||
Regular expressions library(C++11) | ||||
Atomic operations library(C++11) | ||||
Thread support library(C++11) | ||||
Technical Specifications |
C 2b 2b Ostream Dev Null Key
Input/output libraryI/O manipulators | ||||
C-style I/O | ||||
Buffers | ||||
(deprecated in C++98) | ||||
(C++20) | ||||
Streams | ||||
Abstractions | ||||
File I/O | ||||
String I/O | ||||
Array I/O | ||||
(deprecated in C++98) | ||||
(deprecated in C++98) | ||||
(deprecated in C++98) | ||||
Synchronized Output | ||||
(C++20) | ||||
Types | ||||
Error category interface | ||||
(C++11) | ||||
(C++11) |
Global objects | ||||
Member functions | ||||
(C++11) | ||||
Formatted output | ||||
Unformatted output | ||||
Positioning | ||||
Miscellaneous | ||||
(C++11) | ||||
Member classes | ||||
Non-member functions |
Defined in header <ostream> | ||
(1) | ||
template<class CharT, class Traits> basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, | ||
template<class CharT, class Traits> basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
(2) | ||
template<class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, | ||
template<class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Ostream, class T > Ostream&& operator<<( Ostream&& os, | (3) | (since C++11) |
deleted overloads for basic_ostream and UTF character/array | ||
(4) | (since C++20) | |
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, | ||
template<class Traits > basic_ostream<wchar_t,Traits>& operator<<( basic_ostream<wchar_t,Traits>& os, |
Inserts a character or a character string.
ch
. If the type of the character is not CharT
, it is first converted with os.widen(ch). Padding is determined as follows: if os.width()>1
, then os.width()-1
copies of os.fill()
are added to the output character to form the output character sequence.If (out.flags()&std::ios_base::adjustfield)std::ios_base::left, the fill characters are placed after the output character, otherwise before. After insertion, os.width(0) is called to cancel the effects of std::setw, if any.s
.C%2b%2b Ostream Dev Null
- for the first and third overloads (where
CharT
matches the type ofch
), exactlytraits::length(s)
characters are inserted. - for the second overload, exactly std::char_traits<char>::length(s) characters are inserted.
- for the last two overloads, exactly traits::length(reinterpret_cast<constchar*>(s)) are inserted.
C 2b 2b Ostream Dev Null Test
Before insertion, first, all characters are widened using os.widen(), then padding is determined as follows: if the number of characters to insert is less than os.width()
, then enough copies of os.fill()
are added to the character sequence to make its length equal os.width()
. If (out.flags()&std::ios_base::adjustfield)std::ios_base::left, the fill characters are added at the end of the output sequence, otherwise they are added before the output sequence.After insertion, width(0) is called to cancel the effects of std::setw, if any.
s
is a null pointer.Ostream
is a class type publicly and unambiguously derived from std::ios_base.[edit]Parameters
os | - | output stream to insert data to |
ch | - | reference to a character to insert |
s | - | pointer to a character string to insert |
[edit]Return value
os
[edit]Notes
C 2b 2b Ostream Dev Null Code
Before LWG#1203, code such as (std::ostringstream()<<1.2).str() does not compile.
[edit]Example
Output:
[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 1203 | C++11 | overload for rvalue stream returned lvalue reference to the base class | returns rvalue reference to the derived class |
LWG 2534 | C++11 | overload for rvalue stream was not constrained | constrained |
[edit]See also
inserts formatted data (public member function)[edit] |
widens characters (public member function of std::basic_ios<CharT,Traits> )[edit] |