bitset - STL C++

bitset<N>::to_string()

Declaration

template<class XCharType, class XTraits, class XAlloc>
basic_string<XCharType, XTraits, XAlloc> bitset<N>::to_string() const;

Description

This is the member function to_string() for the bitset class template. This function returns a string equivalent of the bitset.

Header Include

#include <bitset>

Example

#include <bitset>
#include <iostream>
#include <string>

int main()
{
	using namespace std;

	// Create a bitset
	bitset<4> qBits(5);
	cout << "bitset<4> : "<< qBits << endl;

	// Output the string representation
	string sBits;
	sBits = qBits.to_string<char, char_traits<char>, allocator<char> >();
	cout << "The string is " << sBits << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

bitset<N>::to_string() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.