Privet/hello/salut/halo/hola!
I have the following code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
using namespace Finder;
int main() {
ifstream in( "1.dat" );
Event *P = new Event( sphere );
double px, py, pz;
while( in>>px>>py>>pz ) {
P->AddParticleRaw( px, py, pz );
}
in.close();
P->Normalize();
cout << P->GetNumber() << " particles in the event." << endl;
OJFRandom::SetSeed( 13 );
double radius = 1.0; // R parameter of eq. (20) in reference [1]
unsigned ntries = 3; // number of tries
JetSearch* js = new JetSearch( P, radius, ntries );
unsigned njets = js->FindJetsForOmegaCut(0.05);
if( njets == 0 ) { cout << "Jets lost." << endl; exit(1); }
Jets* Q = js->GetJets();
cout << Q->GetNumber() << " jets found." << endl;
cout << "Omega: " << Q->GetOmega() << ", "
<< "Y: " << Q->GetY() << ", "
<< "Esoft (normalized): " << Q->GetESoft() << "." << endl;
cout << "The details of the jets (E px py pz):" << endl;
Jet* jet = Q->GetFirst();
while( jet ) {
cout << setw( 10 ) << jet->GetE() << " "
<< setw( 10 ) << jet->GetPx() << " "
<< setw( 10 ) << jet->GetPy() << " "
<< setw( 10 ) << jet->GetPz() << endl;
jet = jet->GetNext();
}
delete P;
delete js;
}
My little practical question is about opening using "ifstream":
I have a directory with some "n.dat" (n=1,2...) files that are used in the code, so just wanted the program to compile all these files one by one.
How to make the program to open not just one file "1.dat", but to open
the next file after compiling this one, for example beginning with
"1.dat" and ending at "10.dat" compiling all of them, and making a
final file with all the data obtained?
I made this code to do that, but unfortunately it doesn't work...
for(int i = 1; i <= 10; i++)
{
std::stringstream ss;
ss << i << ".dat";
}
thks