The C++ bitset to_string method is employed to generate a simple string instance that illustrates the bits within the bitset as a sequence of zeros and ones.
Syntax
Example
string to_string();
Parameter
It does not take any parameter.
Return value
It provides a string that represents the bits stored in the bitset.
Example 1
Example
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<4> b;
b.set();
string mystring =
b.to_string<char,string::traits_type,string::allocator_type>();
cout << "mystring: " << mystring << '\n';
return 0;
}
Output:
Output
mystring: 1111