error: cannot convert 'std::basic_string<char>' to 'char' in assignment

ⅰ亾dé卋堺 提交于 2019-12-11 01:26:22

问题


When I am compiling this code, I always get this error. Here dna is set to char. I want the bit value in the bitset to be converted to a char and the char to a int. If this is not the right way, please guide.

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;
        }
    }
}

回答1:


y.to_string(); returns std::string. It can't be converted to char.

Use this:

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

People, please don't up vote my post. I need it for the "Tenacious" badge.



来源:https://stackoverflow.com/questions/33415325/error-cannot-convert-stdbasic-stringchar-to-char-in-assignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!