Advertisement
Guest User

Untitled

a guest
Apr 6th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. std::vector<std::byte> utils::read_log_file()
  2. {
  3.     std::ifstream ifs(path, std::ios::binary | std::ios::ate);
  4.  
  5.     if (!ifs)
  6.         throw std::runtime_error("Could not load file.");
  7.  
  8.     const auto end = ifs.tellg();
  9.     ifs.seekg(0, std::ios::beg);
  10.  
  11.     const auto size = static_cast<std::size_t>(end - ifs.tellg());
  12.  
  13.     if (size == 0)
  14.         return {};
  15.  
  16.     std::vector<std::byte> buffer(size);
  17.  
  18.     if (!ifs.read(reinterpret_cast<char*>(buffer.data()), buffer.size()))
  19.         throw std::runtime_error("Could not read file.");
  20.  
  21.     return buffer;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement