共用方式為


bitset::to_string

轉換成字串表示的 bitset 物件。

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

傳回值

basic_string 類別的字串物件,而在 bitset 設定的每個位元都有對應的字元 1 和 0 位元字元,如果未設定。

範例

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

需求

標題: <bitset>

命名空間: std

請參閱

參考

bitset Class