I have a project completed where i read in a file and assigns the data in the txt file to a matrix. The problem i am having is that i have 8 data files named data1.txt through data8.txt. I need to find a way to loop through the the data file names by somehow incrementing the number portion of the filename.
here is the segment of code that it will be placed.
#include <iostream>
#include <fstream>
#include "magicSquare.h"
usingnamespace std;
int main () {
int N;
bool flag;
//Open data files to read in data
ifstream myfile ("data1.txt");
if (myfile.is_open())
{
//read in the size of the matrix
myfile>>N;
//declare double pointer matrix
int **matrix = newint*[N];
//Allocate Memory
for(int i = 0; i < N; i++){
matrix[i] = newint [N];
}
//make sure fileis not at end and read int the contents into the array matrix
while(myfile.good()){
for(int i = 0; i < N; i++){
for(int j = 0; j <N; j++){
myfile>>matrix[i][j];
}
}
}
does anyone know how i can loop through the data files to read them all in?
If you need anymore details about the project just let me know.