std::string gethex(char c)
if (c == 'é')
I need a function that converts chars like "á, é, í, ã" to UTF-8 hexadecimal strings...
std::string encode(std::string str)
static std::string unreserved = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.~";
for (int i = 0; i < str.length(); i++ )
char c = str.at(i);
if (unreserved.find(c) != -1)
Yes, but 'c' in this case is just going to be an integer. All characters are represented by the computer as an integer.
The char data type is the same as the int data type, only smaller in size. The character it contains is really the integral ID of a character.
1 2 3
char c = 'a';
if(c == 0x61) // <- this will be true, because 'a'==0x61
So if all you want is to print the character as an integer... then that is the code I already posted:
1 2 3
char example = 'a';
cout << hex << static_cast<int>(example); // prints '61'
But the real question here how is your 'c' encoded? Is it UTF-8 or is it some other encoding?
There is no way to solve this problem unless you know what kind of characters you're dealing with. In the end you just have a bunch of numbers, and in order to do this properly you need to know what those numbers represent.
So where are you getting 'c' from? A file? The user?