Here is the code:
#include <iostream>
#include <fstream>
#include <vector>
#include <iomanip>
std::vector<unsigned char> bytes;
{
std::ifstream in(name, std::ios_base::binary);
bytes.assign(std::istreambuf_iterator<char>(in >> std::noskipws),
std::istreambuf_iterator<char>());
}
According to the reference, the vector.assign
function takes two arguments, first
and last
, and takes anything in between into the vector. And the istreambuf_iterator function takes this form:
istreambuf_iterator( std::basic_istream<CharT,Traits>& is );
istreambuf_iterator( std::basic_streambuf<CharT,Traits>* s );
These are all easy to understand, but in the snippet above, the second iterator initializer takes no arguments, what does it mean?
Also notice that the type of bytes
is unsigned char
, while the type of the iterator is char
, isn't this a mismatch?