Question

What's wrong with this code?

std::vector<unsigned char> newVector;
std::ifstream inFile(fullPath.c_str(), std::ios::in|std::ios::binary);
std::istreambuf_iterator iterator(inFile);

It gives me this:

missing template arguments before 'iterator'

And if I change it to this:

std::istreambuf_iterator<unsigned char> iterator(inFile);

It complains this:

invalid conversion from 'void*' to 
    'std::istreambuf_iterator<unsigned char>::streambuf_type
Was it helpful?

Solution

ifstream is a basic_ifstream<char>, not a basic_ifstream<unsigned char>. Therefore, you need to declare iterator as

std::istreambuf_iterator<char> iterator(inFile);

and it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top