public member function
<bitset>
std::bitset::to_stringtemplate <class charT, class traits, class Alloc> basic_string<charT,traits,Alloc> to_string() const;
template <class charT = char, class traits = char_traits<charT>, class Alloc = allocator<charT>> basic_string<charT,traits,Alloc> to_string (charT zero = charT('0'), charT one = charT('1')) const;
Convert to string
Constructs a basic_string object that represents the bits in the bitset as a succession of zeros and/or ones.The string returned by this function has the same representation as the output produced by inserting the bitset directly into an output stream with operator<<.
Notice that this function template uses the template parameters to define the return type. Therefore, these are not implicitly deduced.
The string returned by this function has the same representation as the output produced by inserting the bitset directly into an output stream with operator<<.
Notice that this function template uses the template parameters to define the return type. The default types for these template parameters select string as the return type.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// bitset::to_string
#include <iostream> // std::cout
#include <string> // std::string
#include <bitset> // std::bitset
int main ()
{
std::bitset<4> mybits; // mybits: 0000
mybits.set(); // mybits: 1111
std::string mystring =
mybits.to_string<char,std::string::traits_type,std::string::allocator_type>();
std::cout << "mystring: " << mystring << '\n';
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4