次の方法で共有


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 ができます。テンプレート関数は、実装します:

ostr << _Right。to_string <CharTypeTraitsallocator<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;
}

出力

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