c++ - 错误: cannot convert 'std::basic_string<char>' to 'char' in assignment

标签 c++ binary char int bitset

当我编译此代码时,我总是收到此错误。这里dna设置为char。我希望将位集中的位值转换为 char,并将 char 转换为 int。如果这不是正确的方法,请指导。

for (std::size_t i = 0; i < myString.size(); ++i)  
{
    std::bitset<8> y(myString[i]);

    dna = y.to_string<char>();
    binary = dna;
    cout << binary << " ";
    while ( binary >= 10) {
        for(int i = 0; i <= 100; ++i) { // loops length of array
            a[i] = binary % 10;
            binary = binary / 10;
        }
    }
}

最佳答案

y.to_string(); 返回 std::string。它无法转换为 char

使用这个:

std::string dna = y.to_string();
unsigned long binary = y.to_ulong();

关于c++ - 错误: cannot convert 'std::basic_string<char>' to 'char' in assignment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33415325/

相关文章:

c - 跳过中间的一些 scanf

c++ - 获取 C++ 引用的地址以传递给指针

java - 将二进制 1 和 0 的整数(或字符串)数组转换为 Java 中的 alpha 等价物

c - 我的 C 程序在不应该打印的时候打印了两个不同的内容

c - 将一个 char 数组分配给另一个,它也是 c 中函数的参数

java - JTable显示char[]

c++ - 是否有用于 Windows 资源加载字符串的有用 C++ 包装器类?

c++ - 如何创建可调整大小的 Qt 缩略图预览?

c++ - 定时发送和接收同一数据包

c# - 优化多维泛型数组的二进制序列化