string fileName[] = {"t0.txt", "t1.txt", "t2.txt", "t3.txt", "t4.txt", "t5.txt", "t6.txt", ""};
int trg[MAXTBLSIZE][MAXTBLSIZE] = {0};
int trgSize; // the number of rows and columns
int trgConstant; // -1 if it is not a perfect triangle or the triangle's constant otherwise
int choice = 1; // to stop the program to allow the user to see the results one table at a time
int maxSum;
ifstream inFile; // input of input file
ofstream outFile; // open output file
for (int i = 0; choice == 1 && fileName[i] != ""; i++)
{
if (readtrg(fileName[i], trg, trgSize))
{
trgConstant = testtrg(trg, trgSize);
printtrg(trg, trgSize);
printResults(trgConstant);
}
else
{
cout << "Error: Input file \"" << fileName[i] << "\" not found!" << endl;
}
cout << "Please enter 1 to continue 0 to stop" << endl;
cin >> choice;
cout<<"Highest Sum:"<<maxSum<<endl;
}
return 0;
}
bool readtrg(string &m, int trg[][MAXTBLSIZE], int &trgSize)
{
ifstream inFile; // input of input file
ofstream outFile; // open output file
inFile.open("m");
}
I'm stuck in here. Can someone explain how I can open the text file from the filename array one by one?
The better thing to do here would be to compile with C++11 (8 years old at this point), so that you can use std::strings there instead of char-pointers.
In fact, C++11 or later has been the default on all mainstream compilers for quite some time now, so you should update your compiler.