iterator copy problem

This is a discussion on iterator copy problem within the C++ Programming forums, part of the General Programming Boards category; Im trying to get a list of words off a text file into an iterator. I tried using the copy ...

  1. #1
    Registered User cdonlan's Avatar
    Join Date
    Sep 2004
    Posts
    49

    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?

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    What's your purpose for this program?

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    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
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21