How to use UTF8 characters in C++
-
What do I need to do to be able to use in C++ UTF8 characters for
char *
andstd::string
, or at least forstd::string
ifchar *
doesn't support it? I'm using std:c++17. I tried the following code to see if it is working without changing anything but it didn't worked and returned┬┴╩╦≡??Γε?
:#include
#includeint main() {
std::string a = "ÂÁÊËðșțâîă";
std::cout << a;
std::cin.get();
} -
What do I need to do to be able to use in C++ UTF8 characters for
char *
andstd::string
, or at least forstd::string
ifchar *
doesn't support it? I'm using std:c++17. I tried the following code to see if it is working without changing anything but it didn't worked and returned┬┴╩╦≡??Γε?
:#include
#includeint main() {
std::string a = "ÂÁÊËðșțâîă";
std::cout << a;
std::cin.get();
}Couple of things: 1. UTF8 literal strings are written as this:
std::string a = u8"ÂÁÊËðșțâîă";
2. Support for UTF8 in regular CMD is VERY bad. I haven't tried much in the new Windows terminal. 3. You might find more stuff about UTF8 in my series of articles on CodeProject.
Mircea
-
What do I need to do to be able to use in C++ UTF8 characters for
char *
andstd::string
, or at least forstd::string
ifchar *
doesn't support it? I'm using std:c++17. I tried the following code to see if it is working without changing anything but it didn't worked and returned┬┴╩╦≡??Γε?
:#include
#includeint main() {
std::string a = "ÂÁÊËðșțâîă";
std::cout << a;
std::cin.get();
} -
Couple of things: 1. UTF8 literal strings are written as this:
std::string a = u8"ÂÁÊËðșțâîă";
2. Support for UTF8 in regular CMD is VERY bad. I haven't tried much in the new Windows terminal. 3. You might find more stuff about UTF8 in my series of articles on CodeProject.
Mircea
Adding u8 worked, thanks. As for CMD it was used only as a testing display, I don't need it in the actual app, and for testing I ended up writing to a file to see if it is working. And where I actually used it, it did worked.