问题
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