public member function
<bitset>

std::bitset::to_string

template <class charT, class traits, class Allocator>
  basic_string<charT,traits,Allocator> to_string() const;
Convert to string
Constructs a basic_string object that represents the bitset as a succession of zeros and ones.

Notice that this function template uses the template parameters to define the return type. Therefore, they are not implicitly deduced by the compiler.

Parameters

none

Return value

String representing the bitset.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// bitset::to_string
#include <iostream>
#include <string>
#include <bitset>
using namespace std;

int main ()
{

  string mystring;
  bitset<4> mybits;     // mybits: 0000

  mybits.set();         // mybits: 1111

  mystring=mybits.to_string<char,char_traits<char>,allocator<char> >();

  cout << "mystring: " << mystring << endl;

  return 0;
}


Output:
1111

See also