Code:
#include <iterator>
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
ifstream datafile("test.txt");
vector<int> bobs;
copy(istream_iterator<int>(datafile),istream_iterator<int>(),back_inserter(bobs));
copy(bobs.begin(), bobs.end(), ostream_iterator<int>(cout, " "));
return 0;
}
I'm really not having any problems with it. What compiler do you use? Perhaps the stream iterators aren't well written on your compiler, mine is Visual C++ 6.0.