Skip to content

Instantly share code, notes, and snippets.

@looopTools
Created February 1, 2019 13:33
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save looopTools/64edd6f0be3067971e0595e1e4328cbc to your computer and use it in GitHub Desktop.
Save looopTools/64edd6f0be3067971e0595e1e4328cbc to your computer and use it in GitHub Desktop.
How to read a file from disk to std::vector<uint8_t> in C++
inline std::vector<uint8_t> read_vector_from_disk(std::string file_path)
{
std::ifstream instream(file_path, std::ios::in | std::ios::binary);
std::vector<uint8_t> data((std::istreambuf_iterator<char>(instream)), std::istreambuf_iterator<char>());
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment