Getline() causes segmentation fault!

Hi,
I am running ver3.05/07.

I need to skip a few lines of text in a text file so i can begin reading the data:

Acoustic data file.
[nxBins][nyBins][nzBins] = [60][60][1000].
Incident Particle = 1.00000e+00TeV pi+

0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00	0.00000e+00...

I try and use the getline() function to read in the first three lines and thus leave me ready to read in the data:

...

  // Read from .dat file.
  ifstream datFile;
  datFile.open("Acoustic.dat"); 

  // need buffers to read first few lines into.
  TString nameOfFile;
  datFile.getline(nameOfFile,128);
  
  TString binInfo;
  datFile.getline(binInfo,128);
  
  TString particleInfo;
  datFile.getline(particleInfo,128);

...
  datFile.close();
...

However this causes a segmentation fault :frowning: Please help me!

Thanx in advance

Jon

i can just read these lines into arrays of characters. maybe using getline function was just overcomplicating things! nevermind :blush:

ifstream::getline needs a char * for the first argument, not a TString.
Try something like:

...
   char line[150];  // As large as the lines that you are reading in

  // Read from .dat file.
  ifstream datFile;
  datFile.open("Acoustic.dat"); 

  // need buffers to read first few lines into.
  datFile.getline(line,128);
  
  datFile.getline(line,128);
  
  datFile.getline(line,128);

...
  datFile.close();
...

Of course, you can use separate arrays for each line
if you wish. You can later convert the char * to a TString
if you need that.

Regards,
Gora