Created
February 14, 2018 12:00
-
-
Save michaeltrainor/90f5a75e2e80c8038007bb00773f060e to your computer and use it in GitHub Desktop.
Read a Binary File to std::vector<BYTE>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iterator> | |
inline std::vector<uint8_t> read_file_binary(const std::string& file_path) | |
{ | |
std::ifstream file_buffer(file_path, std::ios::binary); | |
file_buffer.unsetf(std::ios::skipws); | |
file_buffer.seekg(0, std::ios::end); | |
const auto size = file_buffer.tellg(); | |
file_buffer.seekg(0, std::ios::beg); | |
std::vector<uint8_t> buffer; | |
buffer.reserve(size); | |
buffer.insert(buffer.begin(), std::istream_iterator<uint8_t>(file_buffer), std::istream_iterator<uint8_t>()); | |
return buffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment