改进 “测试 byte字符串长度 及 字节 c++”
代码:
#include <iostream>
#include <string>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char * argv[]) {
string s;
cin>>s;
cout << "字符串长度: "<< s.size()<< endl;
cout << "字符串中的字节: "<< endl;
for (string::size_type i=0; i< s.size(); i++) {
cout <<setfill('0')<< setw(2)<<hex<< (int)(0x0ff &s[i]) << " ";
}
cout << endl;
return 0;
}