-
iterator copy problem
Im trying to get a list of words off a text file into an iterator. I tried using the copy function from fstream but i havent had any luck.
Code:
#include<iostream>
#include <fstream>
#include<iterator>
#include<algorithm>
#include<string>
#include <vector>
using namespace std;
int main()
{
string word;
ifstream infile("dictionary.txt");
istream_iterator< string > in(infile);
istream_iterator< string > eos;
vector< string > dictionary;
copy(in,eos,back_inserter(dictionary));
cout<<dictionary.size();
return 0;
}
any ideas what im doing wrong?
-
What's your purpose for this program?
-
Which compiler do you use?
What kind of problem you're experiencing?
I complied and execute your code with a test file and it worked OK, all words from file was stored in the vector.
Make sure you're file dictionary.txt exists!
- Micko