我只想将每个字符转换为由x
分隔的ascii我希望有65x122x97x45......
#include <iostream>
#include <string>
int main(){
std::string text = "This is some text 123...";
return 0;
}
答案 0 :(得分:0)
这是一个使用stringstreams的解决方案
#include <iostream>
#include <string>
#include <sstream>
int main(){
std::string text = "This is some text 123...";
std::istringstream sin(text);
std::ostringstream sout;
char temp;
while(sin>>temp){
sout<<"x"<<std::hex<<(int)temp;
}
std::string output = sout.str();
std::cout<<output<<std::endl;
return 0;
}
输出是:
x54x68x69x73x69x73x73x6fx6dx65x74x65x78x74x31x32x33x2ex2ex2e