https://github.com/tsnsoft/cpputf8crossplatform
Пример консольной кроссплатформенной программы на C++ с UTF-8 для Visual Studio 2022
https://github.com/tsnsoft/cpputf8crossplatform
console cpp cross-platform linux utf-8 visual-studio windows
Last synced: about 1 month ago
JSON representation
Пример консольной кроссплатформенной программы на C++ с UTF-8 для Visual Studio 2022
- Host: GitHub
- URL: https://github.com/tsnsoft/cpputf8crossplatform
- Owner: tsnsoft
- License: mit
- Created: 2023-11-21T07:43:52.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-21T07:43:57.000Z (over 2 years ago)
- Last Synced: 2025-10-29T22:56:43.732Z (8 months ago)
- Topics: console, cpp, cross-platform, linux, utf-8, visual-studio, windows
- Language: C++
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# CppUTF8CrossPlatform
Пример консольной кроссплатформенной программы на C++ с UTF-8 для Visual Studio 2022

```
#include
#include
#ifdef _WIN32 // Если это Windows
#include
#include
#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 fio; // Создать строковую переменную
std::wcin >> fio; // Считать строку
std::wcout << L"Привет, " << fio << "!" << std::endl; // Вывести строку
std::wcout << L"Размер строки: " << fio.length() << std::endl;
for (int i = 0; i < fio.length(); i++) {
std::wcout << "[" << i << "]: " << fio[i] << " (code: " << int(fio[i]) << ")" << std::endl;
}
}
```