Compartir a través de


bitset::to_string

Converts a bitset object to a string representation.

template<class CharType, class Traits, class Alloc>
   basic_string<CharType, Traits, Alloc> to_string ( ) const;

Return Value

A string object of class basic_string, where each bit set in the bitset has a corresponding character of 1, and a character of 0 if the bit is unset.

Example

// bitset_to_string.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
#include <string>

int main( )
{
   using namespace std;

   bitset<5> b1 ( 7 );

   cout << "The ordered set of bits in the bitset<5> b1( 7 )"
        << "\n that was generated by the number 7 is: ( "
        << b1 << " )" << endl;

   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( 7 )
 that was generated by the number 7 is: ( 00111 )
The string returned from the bitset b1
 by the member function to_string( ) is: 00111.

Requirements

Header: <bitset>

Namespace: std

See Also

Concepts

bitset Class

bitset Members