#include <string>
#include <iostream>
#include <fstream>
usingnamespace std;
void changes(string &);
void changes2(string &);
void table(void);
int main()
{
ifstream fin("names.txt");
string names; // First Name : Last Name
string names2; // Last Name : First Name
table();
while (getline(fin,names)){
changes(names);
cout << names << endl;
changes2(names);
}
system("PAUSE");
return 0;
}
void table(void) // Table Heading
{
cout << "First "" Last " << " Last "" First" <<
" " << " First--Last" << endl;
return;
}
void changes(string &names) // Breaks up names from First/Last into Last/First
{
string lastname,firstname;
firstname = names.substr(0,5);
lastname = names.substr(5,11);
cout << endl << " " << lastname << " " << firstname << endl;
return;
}
void changes2(string &names) // Adds -- between names
{
names.insert(5,"--");
cout << " " << names << endl;
return;
}
First Last Last First First--Last
Adams Billy
Billy Adams
Billy-- Adams
Washington Benny
Benny Washington
Benny-- Washington
Carter Donna
Donna Carter
Donna-- Carter
Smith Eddie
Eddie Smith
Eddie-- Smith
Johnson Ronny
Ronny Johnson
Ronny-- Johnson
Press any key to continue . . .
I wanted the names to be more stacked and in neater rows. Every time I shuffled something around, my code would break. Any tips welcome. Thanks.