open multiple txt files in loop c++ Root

  append, c++, loops, root, txt

I have this code where I put the directory for each file.

#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TSystem.h"
#include "Riostream.h"

#include <iostream>
#include <cmath>
#include <math.h>
#include <cfloat>
#include <string>

using namespace std;

// ---------------------------------------------------------------------------------------

int PosiDataProcess( TString Data_in, TString Root_ou );

// ---------------------------------------------------------------------------------------

void ReadFile(){ const int NFile = 3;

    TString DataIN[NFile], RootOU[NFile] ; int NEvent[NFile] ;
    
    DataIN[0] = "Mydirectory/file_1.txt";
    DataIN[1] = "Mydirectory/file_2.txt";
    DataIN[2] = "Mydirectory/file_3.txt";
      
    RootOU[0] = "Mydirectory/file_1.root";
    RootOU[1] = "Mydirectory/file_2.root";
    RootOU[2] = "Mydirectory/file_3.root";
    

 
    NEvent[0] = 111098 ;
    NEvent[1] = 400000;
    NEvent[2] = 949630;


 for( Int_t Ifl = 0; Ifl < NFile; Ifl++ ) { DataProcess( DataIN[Ifl], RootOU[Ifl] ); }



int DataProcess( TString Data_in, TString Root_ou ) { 


ifstream fileIN; fileIN.open(Data_in);


 while(!fileIN.eof()) {   ...


}
 fileIN.close();

 return 0;  
}

In order to add other input files, how can i do it for multiple files using for example a loop using one DataIN varying with loop.

I already used std.append but it doesn’t work.

Thank you.

Source: Windows Questions C++

LEAVE A COMMENT