Reputation: 223
I am trying to print Unicode characters in C++. My Unicode characters are Old Turkic, I have the font. When I use a letter's code it gives me another characters. For example:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "\u10C00" // My character's unicode code.
cout << str << endl;
return 0;
}
This snipped gives an output of another letter with a 0
just after its end.
For example, it gives me this (lets assume that I want to print 'Ö' letter):
A0
But when I copied and pasted my actual letter to my source snippet, from character-map application in ubuntu, it gives me what I want. What is the problem here? I mean, I want use the character code way "\u10C00"
, but it doesn't work properly. I think this string is too long, so it uses the first 6 characters and pops out the 0
at the end. How can I fix this?
Upvotes: 1
Views: 133
Reputation: 4838
After escape /u
must be exactly 4 hexadecimal characters. If you need more, you should use /U
. The second variant takes 8 characters.
Example:
"\u00D6" // 'Ö' letter
"\u10C00" // incorrect escape code!
"\U00010C00" // your character
Upvotes: 2
Reputation: 6137
std::string
does not really support unicode, use std::wstring
instead.
but even std::wstring
could have problems since it does not support all sizes.
an alternative would be to use some external string class such as Glib::ustring
if you use gtkmm or QString
in case of Qt.
Almost each GUI toolkit and other libraries provide it's own string class to handle unicode.
Upvotes: 2