tut5.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // filesystem tut5.cpp ---------------------------------------------------------------//
  2. // Copyright Beman Dawes 2010
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // See http://www.boost.org/LICENSE_1_0.txt
  5. // Library home page: http://www.boost.org/libs/filesystem
  6. #include <boost/filesystem/fstream.hpp>
  7. #include <string>
  8. #include <list>
  9. namespace fs = boost::filesystem;
  10. int main()
  11. {
  12. // \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
  13. std::string narrow_string ("smile2");
  14. std::wstring wide_string (L"smile2\u263A");
  15. std::list<char> narrow_list;
  16. narrow_list.push_back('s');
  17. narrow_list.push_back('m');
  18. narrow_list.push_back('i');
  19. narrow_list.push_back('l');
  20. narrow_list.push_back('e');
  21. narrow_list.push_back('3');
  22. std::list<wchar_t> wide_list;
  23. wide_list.push_back(L's');
  24. wide_list.push_back(L'm');
  25. wide_list.push_back(L'i');
  26. wide_list.push_back(L'l');
  27. wide_list.push_back(L'e');
  28. wide_list.push_back(L'3');
  29. wide_list.push_back(L'\u263A');
  30. { fs::ofstream f("smile"); }
  31. { fs::ofstream f(L"smile\u263A"); }
  32. { fs::ofstream f(narrow_string); }
  33. { fs::ofstream f(wide_string); }
  34. { fs::ofstream f(narrow_list); }
  35. { fs::ofstream f(wide_list); }
  36. narrow_list.pop_back();
  37. narrow_list.push_back('4');
  38. wide_list.pop_back();
  39. wide_list.pop_back();
  40. wide_list.push_back(L'4');
  41. wide_list.push_back(L'\u263A');
  42. { fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); }
  43. { fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); }
  44. return 0;
  45. }