Skip to content

Instantly share code, notes, and snippets.

@proffix4
Created November 21, 2023 07:01
Show Gist options
  • Save proffix4/76e84fa0989917fe50a9f4d7dc3d1368 to your computer and use it in GitHub Desktop.
Save proffix4/76e84fa0989917fe50a9f4d7dc3d1368 to your computer and use it in GitHub Desktop.
Cpp UTF8 Cross - platform program
#include <stdlib.h>
#include <iostream>
#ifdef _WIN32 // Если это Windows
#include <io.h>
#include <fcntl.h>
#endif
int main(int argc, char** argv)
{
setlocale(LC_ALL, "ru_RU.UTF-8"); // Установить русскую локаль для Linux
#ifdef _WIN32
_setmode(_fileno(stdout), _O_U16TEXT); // Установить Юникод для вывода в консоли Windows
_setmode(_fileno(stdin), _O_U16TEXT); // Установить Юникод для ввода в консоли Windows
_setmode(_fileno(stderr), _O_U16TEXT); // Установить Юникод для вывода ошибок в консоли Windows
#endif
std::wcout << L"Замечательно! Das ist großartig! Wonderful! 精彩的! رائع!\n";
std::wcout << L"Введите имя: ";
std::wstring input; // Создать строковую переменную
std::wcin >> input; // Считать строку
std::wcout << L"Привет, " << input << "!" << std::endl; // Вывести строку
}
@proffix4
Copy link
Author

proffix4 commented Nov 21, 2023

файл нужно сохранить в кодировке UTF-8 с cигнатурой BOM !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment