Skip to content

Instantly share code, notes, and snippets.

@proffix4
Created November 19, 2023 17:01
Show Gist options
  • Save proffix4/55ec235d8a4179d062cf34067d60e752 to your computer and use it in GitHub Desktop.
Save proffix4/55ec235d8a4179d062cf34067d60e752 to your computer and use it in GitHub Desktop.
Console UTF-8 application with boost
#pragma execution_character_set( "utf-8" ) // for MSVC
#include <boost/nowide/args.hpp> // for utf8_to_utf16
#include <boost/nowide/fstream.hpp> // for fstream
#include <boost/nowide/iostream.hpp> // for cout, cerr, cin, clog
using namespace boost::nowide; // for cout, cerr, cin, clog
using std::endl; // for endl
int main()
{
//system("chcp 65001");
std::locale::global(std::locale("En-us.UTF-8")); // for MSVC
cout << "Testing unicode -- English -- Ελληνικά -- Español -- Русский. aäbcdefghijklmnoöpqrsßtuüvwxyz\n";
std::string fio; // = "Иванов Иван Иванович";
cout << "Введите строку: ";
cin >> fio;
cout << "Вы ввели: " << fio << "\n";
cout << "Размер строки: " << fio.length() << endl;
for (int i = 0; i < fio.length(); ++i) {
cout << "[" << i << "]" << fio[i] << " (code: " << int(fio[i]) << ")" << endl;
}
return 0;
}
@proffix4
Copy link
Author

Реально рабочий код для решения проблем с UTF-8 для Windows и компилятора MS!

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