打印字符串的位表示

kal*_*kal 0 c++ printing bit

如何打印字符串的位表示

std::string = "\x80";

void print (std::string &s) {

    //How to implement this
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*itb 6

我投票支持bitset:

void pbits(std::string const& s) { 
    for(std::size_t i=0; i<s.size(); i++) 
        std::cout << std::bitset<CHAR_BIT>(s[i]) << " "; 
} 

int main() {
    pbits("\x80\x70"); 
}
Run Code Online (Sandbox Code Playgroud)