read data from a TString

From: Gilles Quemener (quemener@isn.in2p3.fr)
Date: Tue Nov 16 1999 - 13:51:53 MET





Dear Root Gurus,

I would like to know how one can read some floats and/or integers from
a TString already read from an ASCII file. I mean the equivalent of the 
FORTRAN:

       integer count
       real x, y
       read(10,'(a)') line
* for instance do a test on the first character to see the line is a comment
* line or to see if it contents useful variables and in that case:
       read(line,*) x, y, n

Here is what I would like to perform in Root/C++ for instance:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include <fstream.h>
 
#include "TString.h"
 
int main()
{
  // ouverture fichier d entree:
   ifstream fin;           
   fin.open("essai.dat");
   if (!fin) {
     cout << "Unable to open essai.dat for reading\n";
     return(1);
   }

  // ouverture fichier de sortie:
   ofstream fout;           
   fout.open("essai.out");

  // create base string
   String line;
   Int_t count;
   Float_t x, y;

   ligne.ReadLine(fin);
   cout << line << endl;
  // tests if it is a comment line starting for instance by #,
  // otherwise reads a given number of variables in the line
  // depending of the line in the input file, the number and
  // the nature of the variables may vary, but is always
  // known before compilation  by the user (fortran
  //  programmer reflex!):
   if (line[0] == '#') {
      cout << line << endl;
      fout << line << endl; 
   }    
   else {
   // I would like somnething like that:
            line.sin(x, y, count);                             // reads from the line
   // or like:
             sin << x << y << count << endl;        // reads from the line
   }

 
   fin.close();
   fout.close();

   return 0;
}

Maybe this functionality already exists in the TString class, but I do not know
how to use it.
Thank you for any help,
 

                        Gilles Quemener
-- 
_____________________________________________________________________
Gilles Quéméner                        tél: (33) (0)4-76-28-40-60
Institut des Sciences Nucléaires       fax: (33) (0)4-76-28-40-04
53, Avenue des Martyrs                 http://www.cebaf.gov/~quemener
38026 GRENOBLE cedex FRANCE
 



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET