Hi Stelios,
You need to properly allocate memory for the filenames.
Something like the following should work:
#include <fstream>
#include "TString.h"
#include "TFile.h"
ifstream fin("LIST");
void test() // not returning any value
{
TString files[17];
for(int idx=0; idx<17; idx++) {
fin >> files[idx];
cout << files[idx].Data() << endl;
TFile *f = TFile::Open(files[idx],"read");
// Your code
delete f; // avoid memory leak
}
}
It would make sense to add some error checking.
Regards,
Maarten.
On Tue, 2002-08-27 at 18:12, Stilianos Kesisoglou wrote:
> Hi,
>
> I am having a problem with the following simple piece of code:
>
> 1: #include <fstream>
> 2: #include <cstring>
> 3: #include "TFile.h"
> 4:
> 5: ifstream fin("LIST");
> 6:
> 7: int test()
> 8: {
> 9: char input[17][];
> 10: for (int idx=0; idx<17; idx++)
> 11: {
> 12: fin >> input[idx];
> 13: cout << input[idx] << endl;
> 14:
> 15: TFile *f = new TFile(input[idx],"read");
> 16: .
> 17: . (my code here)
> 18: .
> 19: f->Close();
> 20: }
> 21: }
>
> My intention is to read from a file named "LIST", a list of filenames and then
> open them in sequence, run my code and close them.
>
> Although I can see from the print-out (line 13), that the variable "input[idx]" holds my filename,
> the attempt to open the file fails (line 15).
>
> Can anyone help me?
>
> Thanks !
>
> Stelios.
--
Dr. Maarten Ballintijn
MASSACHUSETTS INSTITUTE OF TECHNOLOGY Email: maartenb@mit.edu
Room 24-410 Phone: +1 (617) 253 4184
77 Massachusetts Avenue Fax: +1 (617) 253 4360
Cambridge, MA 02139, USA http://www.mit.edu/~maartenb
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:06 MET