Skip to content

Instantly share code, notes, and snippets.

@stevenRush
Created April 5, 2014 19:30
Show Gist options
  • Save stevenRush/9996882 to your computer and use it in GitHub Desktop.
Save stevenRush/9996882 to your computer and use it in GitHub Desktop.
#include <exception>
#include <codecvt>
#include <streambuf>
#include <string>
#include <cerrno>
#include <sstream>
using namespace std;
int main()
{
// Setup C++ rtl global default locale
std::locale r1251("Russian_Russia.1251");
std::locale utf8(std::locale(), new std::codecvt_utf8<wchar_t>);
std::locale utf16(std::locale(), new std::codecvt_utf16<wchar_t>);
std::locale::global(r1251);
// Setup locales for wide streams
std::wcout.imbue(r1251);
// For correct io with wcin/wcout disconnect stream from wstream
std::ios::sync_with_stdio(false);
wstring str;
wifstream in1251("C:\\temp\\input_1251.txt");
in1251.imbue(r1251);
getline(in1251, str);
wcout << str << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment