简体   繁体   English

错误:无法转换 &#39;std::basic_string<char> &#39; 到 &#39;char&#39; 赋值

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

When I am compiling this code, I always get this error.当我编译这段代码时,我总是收到这个错误。 Here dna is set to char.这里 dna 设置为 char。 I want the bit value in the bitset to be converted to a char and the char to a int.我希望将 bitset 中的位值转换为 char,将 char 转换为 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;
        }
    }
}

y.to_string(); returns std::string .返回std::string It can't be converted to char .它不能转换为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.我需要它作为“顽强”徽章。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法转换&#39;std :: basic_string <char> 从&#39;到&#39;int&#39;分配 - error: cannot convert ‘std::basic_string<char>’ to ‘int’ in assignment 错误无法转换 &#39;std::string {aka std::basic_string<char> }&#39; 到 &#39;char&#39; 赋值 - C++ - Error cannot convert 'std::string {aka std::basic_string<char>}' to 'char' in assignment - C++ 错误无法转换 'std::string {aka std::basic_string<char> }' 到 'int' 赋值</char> - Error cannot convert 'std::string {aka std::basic_string<char>}' to 'int' in assignment 错误无法转换 'std::string* {aka std::basic_string<char> *}' 到 'node*' 在分配</char> - Error cannot convert 'std::string* {aka std::basic_string<char>*}' to 'node*' in assignment 为什么我收到错误:无法转换 &#39;std::string {aka std::basic_string<char> }&#39; 到 &#39;char*&#39; 赋值? - Why am I getting error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ in assignment? 错误:无法转换&#39;std :: string {aka std :: basic_string <char> 初始化时&#39;&#39;到&#39;char *&#39; - error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘char*’ in initialization std :: string {aka std :: basic_string <char> 分配给&#39;&#39;&#39;char *&#39; - std::string {aka std::basic_string<char>}' to 'char*' in assignment| 错误:无法转换std :: vector <std::basic_string<char> &gt;到std :: string * - error: cannot convert std::vector<std::basic_string<char> > to std::string* C ++错误:无法转换&#39;std :: basic_string <char> &#39;至&#39;const char *&#39; - C++ error: cannot convert ‘std::basic_string<char>’ to ‘const char*’ 错误:无法转换 'std::basic_string<char> ::iterator...' to 'const char* for argument '1'...'</char> - error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM