Last active
April 26, 2016 06:04
-
-
Save matthewjberger/0b6760de2ed41436a19235cfbe1b2d31 to your computer and use it in GitHub Desktop.
Reads a file into a vector of unsigned char
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
typedef unsigned char BYTE; | |
std::vector<BYTE> ReadAllBytes(const std::string& filename) | |
{ | |
using namespace std; | |
ifstream file(filename.c_str(), ios::binary | ios::ate); | |
file >> noskipws; | |
streampos fileSize = file.tellg(); | |
file.seekg(0, ios::beg); | |
vector<BYTE> bytes; | |
bytes.reserve(fileSize); | |
copy(istream_iterator<BYTE>(file), | |
istream_iterator<BYTE>(), | |
back_inserter(bytes)); | |
return bytes; | |
} | |
auto bytes = ReadAllBytes("c:/windows/fonts/arialbd.ttf"); | |
unsigned char* data = bytes.data(); // needs one level of indirection to work properly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment