Advertisement
Brick

File Commands

Jul 11th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. template <typename IterT>
  2. void WriteFile(std::wstring             file,
  3.                std::ios_base::openmode  mode,
  4.                IterT                    begin,
  5.                IterT                    end)
  6. {
  7.     std::copy(
  8.         begin,
  9.         end,
  10.         std::ostreambuf_iterator<char>(std::ofstream(file, mode | std::ofstream::binary)));
  11. }
  12.  
  13. template <typename IterT>
  14. void CreateFile(std::wstring    file,
  15.                 IterT           begin,
  16.                 IterT           end)
  17. {
  18.     WriteFile(file, std::ios_base::trunc, begin, end);
  19. }
  20.  
  21. void CopyFile(std::wstring  from,
  22.               std::wstring  to)
  23. {
  24.     CreateFile(to,
  25.                std::istreambuf_iterator<char>(std::ifstream(from, std::ios_base::binary)),
  26.                std::istreambuf_iterator<char>());
  27. }
  28.  
  29. std::vector<char> ReadFile(std::wstring file)
  30. {
  31.     return std::vector<char>
  32.     (
  33.         std::istreambuf_iterator<char>(std::ifstream(file, std::ios_base::binary)),
  34.         std::istreambuf_iterator<char>()
  35.     );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement