我尝试将以下代码写入我的编译器并编译它:
#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;
}
它应该给我一个二进制输出,但我一直收到错误:
In function `void binary(int)':
no matching function for call to `std::bitset<8u>::to_string()'
我是 C++ 的新手,真的不知道这是什么意思,请帮助我。
最佳答案
我认为 bitset::to_string<T>()
的旧版本接受一个模板参数。所以这应该有效:
cout << bitset<8>(a).to_string<char>() << endl;
关于c++ - 小型 C++ 位集代码的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547676/