There is a UTF-8 string with Russian text: "\xd1\x82\xd0\xb5\xd0\xba\xd1\x81\xd1\x82" .
You must output it to the console so that it works on the following three platforms and compilers:
- Windows and VC ++,
- Windows and MinGW,
- Linux and gcc.
It is assumed that the console font allows you to show at least Russian letters.
It should be noted that the MinGW locales are not fully implemented, and many VC ++ solutions will not work.
MinGW can be taken here .
You can use #ifdef . You can use third-party libraries, such as Boost.
Here is an example of the MinGW solution of the day, but all three platforms need support .
> type main.cpp #include <Windows.h> #include <string> #include <codecvt> #include <locale> int main() { std::wstring_convert<std::codecvt_utf8<wchar_t, 0x10ffff, std::little_endian>, wchar_t> conv; std::wstring ws = conv.from_bytes("[test \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 \xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88]\n"); DWORD _; ::WriteConsoleW(::GetStdHandle(STD_OUTPUT_HANDLE), ws.c_str(), ws.size(), &_, nullptr); } > g++ -std=c++14 -O2 -Wall -pedantic main.cpp && a [test тест テスト]
#ifdef _MSCVER+ a special code for Windows. - VladD