how to print all the names from a text file to console/program in alphabetical order? #c++ :'(

closed account (9wkE8vqX)
//Names inside the text files are: Darwin, Bea, Hans, Denzell
//I want to print them in alphabetically order so the print out in console will
//be like this: Bea, Darwin, Denzell, Hans

void Record2::view(int RunnningCount) //VIEWING THE RECORD'S LIST
{
system("cls"); system("color 1a");
ifstream infile("AddressBook.txt"); //opening the file for reading only
cout << "\n____________________________________________________________________________________ADDRESS BOOK RECORD______________________________________________________________________________________\n\n";
cout << " Full Name: Contact Number: E-Mail Address: Address:";
cout << "\n---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n";
if (infile.is_open()) // verifying if file is open perform the instructions below
{
while (getline(infile, record.fullname), getline(infile, record.contact), getline(infile, record.email), getline(infile, record.address)) //reading the strings inside the text file
{
cout << setiosflags(ios::left) << setw(1) << ++RunnningCount;
cout << setiosflags(ios::right) << setw(31) << record.fullname;
cout << setiosflags(ios::right) << setw(27) << record.contact;
cout << setiosflags(ios::right) << setw(28) << record.email;
cout << setiosflags(ios::right) << setw(99) << record.address << endl; //printing the texts located inside the "AddressBook.txt" in console
}
infile.close(); //closing the file
}
else //if file is not open perform this
{
cout << "File is not open!" << "\n"; rec.viewc2(choice); //calling the function
}
rec.viewc2(choice); //function calling
}
read the names into an array then sort the array and you now have alphabetical order
closed account (9wkE8vqX)
but i used strings :( what's the syntax code for that??
Last edited on
You can still put strings into an array.
closed account (9wkE8vqX)
but how?? :(
closed account (9wkE8vqX)
inside the while? after reading from the text file??
Topic archived. No new replies allowed.