gpt4 book ai didi

c++ - 小型 C++ 位集代码的问题

转载 作者:行者123 更新时间:2023-11-28 07:47:46 25 4
gpt4 key购买 nike

我尝试将以下代码写入我的编译器并编译它:

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com