Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wchar_t mdash[] = { 0x2014, 0x0000 };
- std::wfstream os("filename.txt", std::ios_base::out| std::ios_base::trunc);
- os << mdash;
- assert(!os.bad()); // fails
- void set_locale_on_stream(std::wfstream &os)
- {
- char* locale = setlocale(LC_ALL, "English"); // Get the CRT's current locale.
- std::locale lollocale(locale);
- setlocale(LC_ALL, locale); // Restore the CRT.
- os.imbue(lollocale); // Now set the std::wcout to have the locale that we got from the CRT.
- }
- int foo()
- {
- wchar_t mdash[] = L"— 😃 Test";
- const wchar_t *filename = L"filename.txt";
- wchar_t wbuf[128];
- std::wofstream fout(filename, std::ios::binary);
- if(fout)
- {
- fout.rdbuf()->pubsetbuf(wbuf, 128);
- //optional BOM
- wchar_t bom[1] = { 0xFEFF };
- int x = sizeof(bom);
- fout.write(bom, 1);
- fout << mdash;
- fout.close();
- }
- std::wifstream fin(filename, std::ios::binary);
- if(fin)
- {
- fin.rdbuf()->pubsetbuf(wbuf, 128);
- //optional, skip BOM
- std::wstring wstr;
- if(fin >> wstr)
- MessageBoxW(0, wstr.c_str(), 0, 0);
- fin.close();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment