0

I've just downloaded Visual studio 2019, but I have a problem with string encoding. This is my code in C++:

cout << "èà" << "\n" << endl;

string str;
cout << "Write something: "
cin >> str;
cout << str << endl

The output of the first line is:

èà

If I give "èà" as input at line 5 though, the output is:

èà

I can't understand why. Can you help me please?

The source file encoding is UTF-8, I've already checked.

Please, be specific in your answers, because I've just started with Visual Studio.

Thena3033
  • 1
  • 1
  • `cin` and `cout` don't use UTF-8 in Windows. – Mark Ransom Jun 21 '21 at 19:30
  • 2
    The problem is not VS but encoding of console/terminal which is (based on your description) not utf-8. – t.niese Jun 21 '21 at 19:30
  • I can't test it myself right now but this might help [How do I print UTF-8 from c++ console application on Windows](https://stackoverflow.com/questions/1371012/how-do-i-print-utf-8-from-c-console-application-on-windows), and here the official docs [execution_character_set pragma](https://learn.microsoft.com/en-us/cpp/preprocessor/execution-character-set?view=msvc-160) – t.niese Jun 21 '21 at 19:33
  • Maybe also [How to print UTF-8 strings to std::cout on Windows?](https://stackoverflow.com/questions/45575863/how-to-print-utf-8-strings-to-stdcout-on-windows) – t.niese Jun 21 '21 at 19:35
  • 2
    It's a simple [mojibake](https://en.wikipedia.org/wiki/Mojibake) (Python example: `"èà".encode('utf-8').decode('cp437')` returns `'├¿├á'`). – JosefZ Jun 21 '21 at 19:58
  • @Thena3033 I suggest you could try to set the output code page programmatically: `SetConsoleOutputCP(CP_UTF8);` – Jeaninez - MSFT Jun 22 '21 at 06:53

0 Answers0