mamta rani
mamta rani

Reputation: 133

Problems with small C++ bitset code

I have tried to write the following code into my compiler and compile it:

    #include <iostream>
#include <bitset>
using namespace std;

void binary(int a)
{
 cout << bitset<8>(a).to_string() << endl;
}

int main()
{

binary(16);

system("pause");
return 0;    
}

It should give me a binary output but I keep getting an error:

In function `void binary(int)': 
no matching function for call to `std::bitset<8u>::to_string()' 

I am new to C++ and dont really know what this means, please help me.

Upvotes: 0

Views: 1031

Answers (2)

suvayu
suvayu

Reputation: 4664

I think older versions of bitset::to_string<T>() takes a template argument. So this should work:

cout << bitset<8>(a).to_string<char>() << endl;

Upvotes: 2

Emanuele Paolini
Emanuele Paolini

Reputation: 10172

bitset don't have a to_string method (stl does not use to_string anyway). You should iterate on values yourself.

Upvotes: -1

Related Questions