-2

I would simply like to convert each character to ascii separated by x I would like to have something like 65x122x97x45......

#include <iostream>
#include <string>

int main(){
std::string text = "This is some text 123...";
return 0;
}
user2666310
  • 103
  • 2
  • 15

1 Answers1

0

Here a solution using 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;
}

And the output is:

x54x68x69x73x69x73x73x6fx6dx65x74x65x78x74x31x32x33x2ex2ex2e
SHR
  • 7,940
  • 9
  • 38
  • 57