I am trying to get my program to display multiple files for a user to choose from to load, this is the general code i tried but don't know how to actually put it as (the for loop is what i am having the trouble with)
ofstream save;
ifstream load;
int choice;
int savedplayers;
char *savedgame = new char [15];
load.open("savedplayers");
load >> savedplayers;
load.close();
cout << "1: Load game" << endl;
cout << "2: Save game" << endl;
cin >> choice;
if (choice == 1){
for (int i = 1; i <= savedplayers; i++){
load.open(i);
load >> savedgame;
load.close();
cout << i << ": " << savedgame;
cin >> choice;
cout << savedgame;
}
}
else if (choice == 2){
cout << "Save game as:";
cin >> savedgame;
save.open("savedplayers");
savedplayers++;
save >> savedplayers;
save.close();
save.open(savedplayers);
save >> savedgame;
save.close();
}
}