operator<< (<bitset>)
將位元組序列的文字表示寫入至輸出資料流。
template<class CharType, class Traits, size_t N>
basic_ostream<CharType, Traits>& operator<< (
basic_ostream<CharType, Traits>& ostr,
const bitset<N>& _Right
);
參數
- _Right
要插入輸出資料流為字串型別 bitset<N> 的物件。
傳回值
位元組序列的文字表示在 ostr的。
備註
樣板函式多載 operator<<,允許 bitset 會寫出,而不需要先將它轉換成字串。 樣板函式有效地執行:
_Rightostr << 。to_string <CharType, Traits, allocator<(CharType> > )
範例
// bitset_op_insert.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
#include <string>
int main( )
{
using namespace std;
bitset<5> b1 ( 9 );
// bitset inserted into output stream directly
cout << "The ordered set of bits in the bitset<5> b1(9)"
<< "\n can be output with the overloaded << as: ( "
<< b1 << " )" << endl;
// Compare converting bitset to a string before
// inserting it into the output steam
string s1;
s1 = b1.template to_string<char,
char_traits<char>, allocator<char> >( );
cout << "The string returned from the bitset b1"
<< "\n by the member function to_string( ) is: "
<< s1 << "." << endl;
}
Output
The ordered set of bits in the bitset<5> b1(9)
can be output with the overloaded << as: ( 01001 )
The string returned from the bitset b1
by the member function to_string( ) is: 01001.
需求
標題: <bitset>
命名空間: std