Jūs esateŽurnalai / Ernestas Kardzys's blog / C++. How to print non ASCII characters?
C++. How to print non ASCII characters?
We have some additional letters in the Lithuanian language: ą, č, ę, ė, į, š, ų, ū, ž (if you can't see them - change the encoding of your browser into Unicode). The point is, that cout can not print those letters. So, how to print Unicode letters in the console?
The solution:
ernestas@ernestas-laptop:~$ g++ code.cpp ernestas@ernestas-laptop:~$ ./a.out Žuvis Šamas Paštas ernestas@ernestas-laptop:~$ cat code.cpp #include <iostream> #include <fstream> #include <wchar.h> using namespace std; void print(const wchar_t *text) { wcout << text << endl; } int main() { locale::global(locale("en_US.utf8")); wcout << L"Žuvis" << endl; print(L"Šamas"); wchar_t text[] = L"Paštas"; print(text); return 0; } ernestas@ernestas-laptop:~$P.S. The translation: Žuvis - The Fish Šamas - The Sheatfish Paštas - The Post


Linux'e?
string text = "ąčęėęį";
cout << text << endl;
Taip man irgi su gcc veikia :) Tik ant Visual Studio nenori ;/
Keistas dalykas, bet pas mane konsolėj be jokių papildomų include'ų ir wcout'ų rodomos lietuviškos raidės. Iškyla natūralus klausimas: kam tada visa tai su wchar ir t.t.?
Skelbti naują komentarą