Guest User

Untitled

a guest
Nov 16th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. wchar_t mdash[] = { 0x2014, 0x0000 };
  2.  
  3. std::wfstream os("filename.txt", std::ios_base::out| std::ios_base::trunc);
  4. os << mdash;
  5. assert(!os.bad()); // fails
  6.  
  7. void set_locale_on_stream(std::wfstream &os)
  8. {
  9. char* locale = setlocale(LC_ALL, "English"); // Get the CRT's current locale.
  10. std::locale lollocale(locale);
  11. setlocale(LC_ALL, locale); // Restore the CRT.
  12. os.imbue(lollocale); // Now set the std::wcout to have the locale that we got from the CRT.
  13. }
  14.  
  15. int foo()
  16. {
  17. wchar_t mdash[] = L"— 😃 Test";
  18. const wchar_t *filename = L"filename.txt";
  19.  
  20. wchar_t wbuf[128];
  21. std::wofstream fout(filename, std::ios::binary);
  22. if(fout)
  23. {
  24. fout.rdbuf()->pubsetbuf(wbuf, 128);
  25.  
  26. //optional BOM
  27. wchar_t bom[1] = { 0xFEFF };
  28. int x = sizeof(bom);
  29. fout.write(bom, 1);
  30.  
  31. fout << mdash;
  32. fout.close();
  33. }
  34.  
  35. std::wifstream fin(filename, std::ios::binary);
  36. if(fin)
  37. {
  38. fin.rdbuf()->pubsetbuf(wbuf, 128);
  39.  
  40. //optional, skip BOM
  41. std::wstring wstr;
  42. if(fin >> wstr)
  43. MessageBoxW(0, wstr.c_str(), 0, 0);
  44. fin.close();
  45. }
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment