L
LT
Good day!
I'm trying to read in values from input file (in_file)
and add them to another file (out_file)
Repeat the same process but opening a different file...
I'm trying to use a combination of for loop (2 run, does not work) and while
loops.
Any help on this will be great...
This is probably a very, very simple question and I apologize for that.
I declared the files as follow
ifstream in_file;
ofstream out_file;
out_file.open("outputNumbers.txt", ios:ut);
//I'll like to use a loop for
this...
for (int i=1; i<5; i++)
{
out_file <<"\n **running run number "<<i;
out_file <<"\n ----------------------";
if (i==1)
{
in_file.open("in_data", ios::in); //Opening my first input
file
while (!in_file.eof()) // while the file is not empty
{
in_file >> number;
out_file<<"\nNumber from the in_data file is "<<number;
}
in_file.close(); // closing the file, so that I can open a
different file
}
if (i==2) // on my second run, this should happen, BUT it isn't
{
in_file.open("in_bonus", ios::in);
while (!in_file.eof())
{
out_file<<"\nOpening in_Bonus file";
in_file >>number;
out_file <<"\nNumber from the in_bonus file is "<<number;
}
in_file.close();
}
}
}
-LT
I'm trying to read in values from input file (in_file)
and add them to another file (out_file)
Repeat the same process but opening a different file...
I'm trying to use a combination of for loop (2 run, does not work) and while
loops.
Any help on this will be great...
This is probably a very, very simple question and I apologize for that.
I declared the files as follow
ifstream in_file;
ofstream out_file;
out_file.open("outputNumbers.txt", ios:ut);
//I'll like to use a loop for
this...
for (int i=1; i<5; i++)
{
out_file <<"\n **running run number "<<i;
out_file <<"\n ----------------------";
if (i==1)
{
in_file.open("in_data", ios::in); //Opening my first input
file
while (!in_file.eof()) // while the file is not empty
{
in_file >> number;
out_file<<"\nNumber from the in_data file is "<<number;
}
in_file.close(); // closing the file, so that I can open a
different file
}
if (i==2) // on my second run, this should happen, BUT it isn't
{
in_file.open("in_bonus", ios::in);
while (!in_file.eof())
{
out_file<<"\nOpening in_Bonus file";
in_file >>number;
out_file <<"\nNumber from the in_bonus file is "<<number;
}
in_file.close();
}
}
}
-LT