I try to output Russian letters in VC ++ 2017 to the console. Setlocale and chcp did not help, only _setmode (_fileno (stdout), _O_U16TEXT) helped; wcout << L "How many cars to put in the catalog?";
But now when I try to output a string, it throws some exception after the output "Here is your collection:". What is the problem? Here is the code:
#include <iostream> #include <string> #include <io.h> #include <fcntl.h> int main(void) { using namespace std; _setmode(_fileno(stdout), _O_U16TEXT); struct car { string name; int year; }; int qnt; wcout << L"Π‘ΠΊΠΎΠ»ΡΠΊΠΎ Π°Π²ΡΠΎΠΌΠΎΠ±ΠΈΠ»Π΅ΠΉ ΠΏΠΎΠΌΠ΅ΡΡΠΈΡΡ Π² ΠΊΠ°ΡΠ°Π»ΠΎΠ³?"; cin >> qnt; car *cars = new car[qnt]; for (int i = 0; i < qnt; i++) { wcout << L"ΠΠ²ΡΠΎΠΌΠΎΠ±ΠΈΠ»Ρ #" << i + 1 << endl; cin.get(); wcout << L"ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»Ρ:"; getline(cin, cars[i].name); wcout << L"Π£ΠΊΠ°ΠΆΠΈΡΠ΅ Π³ΠΎΠ΄ Π²ΡΠΏΡΡΠΊΠ°:"; cin >> cars[i].year; } wcout << L"ΠΠΎΡ Π²Π°ΡΠ° ΠΊΠΎΠ»Π»Π΅ΠΊΡΠΈΡ: " << endl; for (int i = 0; i < qnt; i++) { cout << cars[i].name << " "; cout << cars[i].year; } system("pause"); return 0; }