Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
bitset
bitset::bitset
bitset operators
member functions:
bitset::any
bitset::count
bitset::flip
bitset::none
bitset::operator[]
bitset::reset
bitset::set
bitset::size
bitset::test
bitset::to_string
bitset::to_ulong


bitset::to_string

public member function
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