-
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.
-
-
sorry, fixed that.
Sorry first time here, I used the code tag now . :D
Now what can I do to close the ifstream?