C++ 如何将字符串中的每个字符转换为ascii值

C++ 如何将字符串中的每个字符转换为ascii值,c++,C++,我只想将每个字符转换为ascii码,用x分隔,我想用65x122x97x45…… #include <iostream> #include <string> int main(){ std::string text = "This is some text 123..."; return 0; } #包括 #包括 int main(){ std::string text=“这是一些文本123…”; 返回0; } 这里有一个使用stringstreams的解决方案 #i

我只想将每个字符转换为ascii码,用
x
分隔,我想用
65x122x97x45……

#include <iostream>
#include <string>

int main(){
std::string text = "This is some text 123...";
return 0;
}
#包括
#包括
int main(){
std::string text=“这是一些文本123…”;
返回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