#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
int main()
{
std::ifstream file("data.bin", std::ios::binary );
if( file.fail() )
{
std::cout << "File does not exist or could not open file";
return 0;
}
std::vector<short> buffer;
std::copy(
std::istreambuf_iterator<char>( file ),
std::istreambuf_iterator<char>(),
std::back_inserter( buffer )
);
return 0;
}
This only gives me ranges of char values (-128, 128).
I thought using istreambuf_iterator<short>
would give me what I want but it throws an "invalid conversion" error.
What can I do to read binary values that are in the short
range?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…