Hi, I'm having a problem with displaying names from a text file. I'm passing the names from the text file to an array that will be sorted, but I'm not getting the names to show like I want them to.
It should display the different names as Last, First
But it comes up as
Last,
First
I believe that I'm not passing the names from the text file to the array properly, but I'm not sure what I should do.
#include<iostream>
#include<fstream>
using namespace std;
//function prototypes
void selectionSort(string[], int);
void showArray(string[], int);
int main()
{
//Input file stream object
ifstream inputFile;
//constant for number of names
const int NUM_NAMES = 20;
//array that holds names
string names[NUM_NAMES];
//open the file
inputFile.open("namesFile.txt");
// Read names from file into array
for(int count = 0; count < NUM_NAMES; count++)
inputFile >> names[count];
//close file
inputFile.close();
cout<<"Unsorted names :\n\n";
//show and then sort names
showArray( names, NUM_NAMES );
selectionSort( names, NUM_NAMES );
//clear screen for readablity
system("cls");
//show sorted names
cout<<"Sorted names :\n\n";
showArray( names, NUM_NAMES );
return 0;
}
I'm not looking for someone to do my homework for me, I just need a push in the right direction.