Namespaces
Variants
Actions

std::bitset<N>::to_string

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
 
(1)
template< class CharT, class Traits, class Allocator >

std::basic_string<CharT, Traits, Allocator>
    to_string( CharT zero = CharT('0'),

               CharT one = CharT('1') ) const;
(until C++11)
template<

    class CharT = char,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>
>
std::basic_string<CharT, Traits, Allocator>
    to_string( CharT zero = CharT('0'),

               CharT one = CharT('1') ) const;
(since C++11)
(constexpr since C++23)
template< class CharT, class Traits >

std::basic_string<CharT, Traits>
    to_string( CharT zero = CharT('0'),

               CharT one = CharT('1') ) const;
(2) (until C++11)
template< class CharT >

std::basic_string<CharT> to_string( CharT zero = CharT('0'),

                                    CharT one = CharT('1') ) const;
(3) (until C++11)
std::string to_string( char zero = '0', char one = '1' ) const;
(4) (until C++11)

Converts the contents of the bitset to a string. Uses zero to represent bits with value of false and one to represent bits with value of true.

The resulting string contains N characters with the first character corresponds to the last (N-1th) bit and the last character corresponding to the first bit.

All template type arguments need to be provided because function templates cannot have default template arguments. Overloads (2-4) are provided to simplify the invocations of to_string:

2) Uses the default allocator