Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1.     std::basic_ifstream<uint8_t> f;
  2.     std::ios_base::iostate exceptionMask = f.exceptions() | std::ios::failbit;
  3.     f.exceptions(exceptionMask);
  4.  
  5.     try {
  6.         f.open(file_name, std::ios::binary);
  7.  
  8.         f.seekg(std::ios::end);
  9.         this->buffer.reserve(f.tellg());
  10.         f.seekg(std::ios::beg);
  11.  
  12.         this->buffer.assign(
  13.             std::istreambuf_iterator<uint8_t>(f),
  14.             std::istreambuf_iterator<uint8_t>()
  15.         );
  16.     }
  17.     catch (std::ios_base::failure& e) {
  18.         std::cerr << e.what() << '\n';
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement