I recall once seeing a clever way of using iterators to read an entire binary file into a vector. It looked something like this:
#include <fstream>
#include <ios>
#include <iostream>
#include <vector>
using namespace std;
int main() {
ifstream source("myfile.dat", ios::in | ios::binary);
vector<char> data(istream_iterator(source), ???);
// do stuff with data
return 0;
}
The idea is to use vector
's iterator range constructor by passing input iterators that specify the entire stream. The problem is I'm not sure what to pass for the end iterator.
How do you create an istream_iterator
for the end of a file? Am I completely misremembering this idiom?