[英]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.