Strings and Sorting

My code (below) is supposed to read in a list of numbers and names from a file.
ex)
2942893
Bill Scott
Jones
3823920578
Mark Thomas
Sorensen
2931093489
John
Hansen

Then it is supposed to put them into this format (alphabetized by last name and with hyphens added into the numbers).
ex)
Hansen, John 293-109-3489
Jones, Bill Scott 294-2893
Sorensen, Mark Thomas 382-392-0578

So far, I can read in the names and numbers. All I have to do is use selectionSort and add hyphens. How do I do this? Also, when I cout everything I have a bunch of commas after that keep going down the list as if there were still more names and numbers. Thanks for any help.

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

const int ROWS=50;

int main () {
ifstream fin;
fin.open("phoneData.txt");
if(fin.fail()){
cout << "Error opening file.\nShutting down." << endl;
return 0;
}

string phoneNumbers[ROWS];
string firstName[ROWS];
string lastName[ROWS];
string fullName[ROWS];

for(int index=0; index<ROWS; index++){
fin >> phoneNumbers[index];
fin.ignore();
getline(fin, firstName[index], '\n');
getline(fin, lastName[index], '\n');

fullName[index]=lastName[index]+", "+firstName[index];
}
}

Topic archived. No new replies allowed.