Thread: vector <fstream*> problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    32

    vector <fstream*> problem

    hi, I can't understand how use it:
    Code:
    		
    string temp_str;
    vector <fstream*> file;
    for (int i=0; i < 2; i++) {
       fstream* ff = new fstream;
       *ff << i.toString(); //pseudo-code
        file.push_back(ff);
         ff->close();
    }
    // now the files are filled with two different strings  ---- MY problem begin here...
    vector <fstream*>::iterator fIter; int i;
    for (fIter = file.begin(), i=0; fIter != file.end(); ++fIter, i++) {
             (*fIter)->open(computeFileName(i).c_str(), ios_base::in); 
             *(fIter[i]) >> temp_str;
              //*(fIter[0]) >> temp_str; //with this, it works! why?
    }
    I have 3 files to open and read. In temp_str goes the right string only when i=0; other times when I=1,2 temp_str take nothing. It works all with *(fIter[0]) >> temp_str;
    Anyone could explain me how understand this vector??
    thanks
    Last edited by mickey0; 07-18-2007 at 06:00 AM.

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, 11: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