#include <string>
int main() {
std::string str("Вася");
for(unsigned char c : str)
printf("%%%X", c);
printf("\n");
return 0;
}
%D0%92%D0%B0%D1%81%D1%8F
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
int main() {
std::string str("Вася");
std::stringstream stream;
stream << std::hex;
for(unsigned char c : str)
stream << '%' << std::setw(2) << static_cast<int>(c);
std::cout << stream.str() << std::endl;
return 0;
}