#include
#include
#include
#include
int main()
{
std::ifstream file(\"data.bin\", std::ios::bin
Here's my recommended Spirit approach:
#include
#include
namespace qi = boost::spirit::qi;
int main()
{
std::ifstream file("data.bin", std::ios::binary);
if(!file)
std::cout << "File does not exist or could not open file";
boost::spirit::istream_iterator f(file), l;
std::vector buffer;
bool ok = qi::parse(f, l, *qi::word, buffer);
}
Of course, there is qi::dword
, qi::qword
, big-endian/little-endian variatations etc.:
You can look at wchar_t
#include
#include
#include
#include
int main()
{
std::wifstream file("data.bin", std::ios::binary );
if( file.fail() )
{
std::cout << "File does not exist or could not open file";
return 0;
}
std::vector buffer;
std::copy(
std::istreambuf_iterator( file ),
std::istreambuf_iterator(),
std::back_inserter( buffer )
);
}
I'm not too sure whether the actual size of wchar_t is implementation defined.