为什么我会收到错误消息?对我来说它看起来很简单。另外,这是做我想做的最好的方法吗?
#include <iostream>
#include <string>
int main() {
char j = "J";
std::cout << bitchar(j);
return 0;
}
std::string bitchar(char c) {
std::string s;
unsigned thisdivisor = (unsigned)c;
while (!thisdivisor) {
s += thisdivisor % 2 ? '0' : '1';
thisdivisor /= 2;
}
return s;
}