<p>If I have a string "12 23 34 56"</p>

<p>What's the easiest way to change it to "\x12 \x23 \x34 \x56"?</p>

```
```
string s = "12 23 34 45";
stringstream str(s), out;
int val;
while(str >> val)
    out << "\\x" << val << " "; // note: this puts an extra space at the very end also
                               //       you could hack that away if you want

// here's your new string
string modified = out.str();
```
```