Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <file.hpp>
- #include <fstream>
- std::vector<char> file_readBin(const std::string& filePath){
- //open file in binary mode, preemptively seeking to eof
- std::ifstream file(filePath, std::ios::binary | std::ios::ate);
- if(!file.is_open()) throw "File failed to open";
- std::streamsize fileSize = file.tellg(); //size of file, in bytes
- file.seekg(0, std::ios::beg); //seek to start of file
- //read file data into a newly-created buffer
- std::vector<char> buffer(static_cast<std::size_t>(fileSize));
- if(!file.read(buffer.data(), fileSize)) throw "File couldn't be read from";
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement