Skip to content

Instantly share code, notes, and snippets.

@zhuker
Created January 16, 2023 23:05
Show Gist options
  • Save zhuker/2c3a646a37fb68c10fe068e9e09ac67b to your computer and use it in GitHub Desktop.
Save zhuker/2c3a646a37fb68c10fe068e9e09ac67b to your computer and use it in GitHub Desktop.
static std::vector<char> readAllBytes(char const* filename)
{
std::ifstream ifs(filename, std::ios::binary | std::ios::ate);
std::ifstream::pos_type pos = ifs.tellg();
if (pos == 0)
{
return std::vector<char>{};
}
std::vector<char> result(pos);
ifs.seekg(0, std::ios::beg);
ifs.read(&result[0], pos);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment