Thread: ifstream.close problem

  1. #1
    Registered User AzraelKans's Avatar
    Join Date
    Oct 2002
    Posts
    5

    Question ifstream.close problem

    Im trying to do this in dev c++

    Im basically open a large list which contains filenames to parse
    and store the results.

    Now what im trying to do here is to open an close a file in order to be able to "parse" a number of files (which are saved in a list)
    Code:
     ifstream l_file("list.txt"); //text containing list of files.
      ifstream a_file; //the file to be parsed
      ofstream b_file("final.txt"); //file which will be filled with the result
    
      while (!l_file.eof()) //open the file list
      {
       l_file>>fname; //send the file to the filename
       a_file.open(fname); //open the text containing emails
       cout<<"filename:"<<fname<<":"<<a_file.is_open()<<endl;
       while (!a_file.eof())
       {
            a_file>>str;
            if (parseline(str)!='\0')
            {
                cout<<"linea:"<<str<<endl;
                cout<<"lineap :"<<parseline(str)<<endl;
                b_file<<parseline(str)<<endl;      //save the parsed data
            }
       }
    
       a_file.close();
       a_file.clear();
      }
      l_file.close ();
      b_file.close ();
    
    getch();
    return 0;
    }
    It looks like it should work right? well when I try to open the a_file for a second time, the program crashes. thats why I added a_file.clear but it doesnt work. is there a way to use an ifstream with 2 diferent files without crashing? how do you actually close a filestream?

    p.s.
    oh yeah, the list contains the same file like this

    example.txt
    example.txt

    so is not a file missing problem.
    Last edited by AzraelKans; 10-25-2002 at 06:47 PM.

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    If I had a penny...
    http://cboard.cprogramming.com/showt...threadid=13473
    Read that, and come back.

  3. #3
    Registered User AzraelKans's Avatar
    Join Date
    Oct 2002
    Posts
    5

    Talking sorry, fixed that.

    Sorry first time here, I used the code tag now .

    Now what can I do to close the ifstream?
    Last edited by AzraelKans; 10-25-2002 at 06:58 PM.

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