This is the problem, you need to pull out all the values from the line containing something like "\ x1 \ x2 \ xd \ x3" and recalculate their bytes.
std::string s= "\x1\x2\xd\x3" const char* y = s.c_str(); ????
This is what you need? :)
void outbytes(const std::string& s) { std::cout << std::setfill('0') << std::hex; for(unsigned char c: s) std::cout << "\\x" << std::setw(2) << static_cast<int>(с) << " "; std::cout << std::endl; }
c
to unsigned char give, if you want all bytes only 2 hexes to be output. - avpauto
replace unsigned char
. - StateItPrimitivesigned char
, that for unsigned char
will display a character . If you need a code - you have to lead to numeric types . - αλεχολυτSource: https://ru.stackoverflow.com/questions/508123/
All Articles
int sum = 0; for (int i = 0; i < s.length(); i++) sum += (unsigned char)s[i]; cout << sum << '\n';
int sum = 0; for (int i = 0; i < s.length(); i++) sum += (unsigned char)s[i]; cout << sum << '\n';
, and you can still a bunch of ways, but I think the idea of access to eachchar
inside thestring
you caught. - avp