Hello, I am trying to print out these names from a data file in alphabetical order with the scores attached to the names. Can someone be of some assistance and write some code please?
struct person
{
string firstName, lastName;
int score;
};
int main()
{
ifstream info1, info2;
info1.open("info1.txt");
if(!info1)
{
cerr << "Error: info1 could not be opened" << endl;
exit(1);
}
info2.open("info2.txt"); // opens the file
if(!data2) // file couldn't be opened
{
cerr << "Error: info2 could not be opened" << endl;
exit(2);
}
Why are you reading from two files? Isn't the data all in one file?
If that's the case, then you will need an array (or vector) of person records.
You will need to read the data file adding each record to the array until you reach end of file.
You will then need to sort the array.
Not going to write the code for you. We don't do homework. If you run into problems, post back and we will try and help.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.