cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : bitset : to_string
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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

// 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

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

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us