Sdílet prostřednictvím


operator<< (<bitset>)

Vloží textovou reprezentací posloupnosti bitů do výstupního datového proudu.

template<class CharType, class Traits, size_t N> 
   basic_ostream<CharType, Traits>& operator<< ( 
      basic_ostream<CharType, Traits>& ostr, 
      const bitset<N>& _Right 
   );

Parametry

  • _Right
    Objekt typu bitset<N> který má být vložen do výstupního datového proudu jako řetězec.

Vrácená hodnota

Textovou reprezentací posloupnosti bitů v ostr.

Poznámky

Přetížení funkce šablony operátor<<, umožňující bitset zapsáno bez počátečního převodu na řetězec.Funkce šablony účinně provede:

ostr<< _Right.to_string<CharType, Traits, allocator<CharType>> ( )

Příklad

// 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;
}

Výsledek

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.

Požadavky

Záhlaví:<bitset>

Obor názvů: std