Currently created a piece of code that is able to output from a text file, I am reading the text and the putting each different piece of information into an array.
I have used 4 different arrays, as there is 4 different types of information I want to store. The code for this is working as expected, but I am unsure how I can now sort the information in a way which 1 of the arrays is sorted alphabetically, with all the corresponding arrays to stay in line and be output at the correct time.
void displayfile(){
string filename1;
string rartist[NUM];
string rtitle[NUM];
string ryear[NUM];
string rcategory[NUM];
ifstream openFile;
int counter = 0;
int continu
bool error = false;
cout << "test";
do{
//Loop to retrieve the file name from user, then open file
do{
cout << "Please enter the name of the menu you would like to open: ";
cin >> filename1;
filename1 += ".txt";
openFile.open(filename1.c_str());
if(openFile.fail()){
cerr << "Check spelling of file name.\n";
error = true;
}
//Storing text from file into arrays
}while(error == true);
while(getline( openFile, rartist[counter], ':') && getline( openFile, rtitle[counter], ':') &&
getline( openFile, ryear[counter], ':') && getline( openFile, rcategory[counter])){
counter++;
}
//outputting the information stored in the array
cout << "ARTIST " << " DVDTITLE " << " YEAR " << " CATEGORY \n";
for(int i = 0; i < counter; i++){
cout << rartist[i] << " " << rtitle[i] << " "
<< ryear[i] << " " << rcategory[i] << "\n";
}
cout << "\n\nIf you would like to read another file, Press 1: ";
cin >> continu;
}while(continu == 1)
}
This is the function that I am using to display the text currently.