I need to deduce length of text file and save the numbers it contains (int) in a vector. I wrote' the code below:
std::ifstream data(file_in);
unsigned length=distance(std::istream_iterator<int>(data),std::istream_iterator<int>());
copy(std::istream_iterator<int>(data),std::istream_iterator<int>(),vec.begin());
However, even if the length is correct, no number is saved into my vector, but if I remove the second line numbers are saved. I think it's a problem of iterator... but I don't know how to solve it, do I need to use the function advance?