having a problem with infile streams

mdobbs@uvic.ca
Sun, 18 Jul 1999 15:11:27 -0700 (PDT)


Hello,

I'm trying to read ascii files with ifstreams. My codes work well in stand
alone c++, but I'm having trouble getting them to work in ROOT- either as
a shared lib or as a macro. Here's a simplified example of the problem:

This macro works:
***********main.C
#include <iostream.h>
#include <fstream.h>
main() {
char* filename = "datacard";
ifstream infile(filename, ios::in);
float infloat;
infile >> infloat;
infile.close();
cout << "the read float is "<< infloat << endl;
}

BUT an ~equivalent class defining macro causes a segmentation violation:
***********main2.C
#include <iostream.h>
#include <fstream.h>
class readfloat {
public:
readfloat() {}
readfloat(char* filename ) {
ifstream infile(filename, ios::in);
float infloat;
infile >> infloat;
infile.close();
cout << "the read float is "<< infloat << endl;
}
};

in ROOT:
root [8] .L main2.C
root [9] a = new readfloat("datacard");
*** Break *** segmentation violation

where the file datacard is an ascii file, one float per line.

I'm using root_v2.21.HP-UX.B.10.20
Thanks in advance, MATT

_________________________________________________________________________
Matt D O B B S
Department of Physics and Astronomy CERN Address:
University of Victoria 40-1-C15, ATLAS Bldg.
P.O. Box 3055 Office Tel: 41.22.76.71272
Victoria, British Columbia
Canada V8W 3P6
Email: mdobbs@uvic.ca Matthew.Adam.Dobbs@Cern.CH
Office Tel.: (250) 721-7728 http://wwwhep.phys.uvic.ca/~mdobbs/
Home Tel.: (250) 995-1235