Skip to content

Instantly share code, notes, and snippets.

@vxcute
Last active April 14, 2021 02:12
Show Gist options
  • Save vxcute/a1a2b71a39534c3ef80a289f28aed89d to your computer and use it in GitHub Desktop.
Save vxcute/a1a2b71a39534c3ef80a289f28aed89d to your computer and use it in GitHub Desktop.
// simple way to read a Binary File using modern c++
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
template <typename T>
auto ReadBinFile(std::string FilePath) -> std::vector<T>
{
std::ifstream File(FilePath, std::ios::binary);
std::vector<unsigned char> FileBuf(std::istreambuf_iterator<char>(File), {});
return FileBuf;
}
int main()
{
std::vector<uint8_t> FileBuf = ReadBinFile<uint8_t>("path");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment