A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/bitset/bitset/to_string/ below:

public member function

<bitset>

std::bitset::to_string
template <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.



Parameters none
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. The default types for these template parameters select string as the return type.



Parameters
zero, one
Character values to represent zero and one.

Return value A string representing the bits in the bitset.

Example
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;
}

Output:


Data races The bitset is accessed.

Exception safetyStrong guarantee: if an exception is thrown, there are no changes in the bitset.

See also
bitset::to_ulong
Convert to unsigned long integer (public member function)
bitset::bitset
Construct bitset (public member function)

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