Load a binary file with C++

less than 1 minute read

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool LoadBinaryFile(std::wstring const& path, std::vector<unsigned char>& data)
{
	try
	{
		std::basic_ifstream<unsigned char, std::char_traits> ifs(path, std::ios::binary);
		std::istreambuf_iterator streamIter(ifs);
		data.clear();
		std::copy(streamIter, std::istreambuf_iterator(), std::back_inserter(data));
		return true;
	}
	catch(...)
	{
	}
	return false;
}