Jūs esateŽurnalai / Ernestas Kardzys's blog / C++. How to print non ASCII characters?

C++. How to print non ASCII characters?


ParašėErnestas Kardzys - 2009 Rugsėjo 09

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ą

Šio laukelio turinys bus laikomas privatus ir nerodomas viešai.
  • Web puslapiu adresai ir el. pašto adresai automatiškai tampa nuorodomis.
  • Leidžiamos HTML žymės: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Linijos ir paragrafai atskiriami automatiškai
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

Daugiau informacijos apie teksto formatavimą

CAPTCHA
Šis klausimas yra skirtas įsitikinti, jog jūs esate žmogus, ir sustabdyti automatinį šlamšto siuntimą.