Reads in strings from a file

I have to modify a program that I wrote for my last code. I need to modify it so it reads in 20 strings from a file. The data can be found in the names.txt file. I would like some advice on my code because it is not working

[code]
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

void selectionSort(string [], int);
void showArray(string [], int);

int main()
{
const int SIZE = 29;
string array[SIZE];
int i=0;
string name;

ifstream in ("names.txt");

if (in.is_open())
{
while (! in.eof() )
{
getline (in,name);
array[i] = name;
cout << array[i] << endl;
i++;
}
cout<<"\n";

in.close();
}

cout << "\tThe unsorted string is: \n";
showArray(name, SIZE);
selectionSort(name, SIZE);
cout << "\n\tThe sorted string is: \n";
showArray(name, SIZE);
system("pause");
return 0;
}


void selectionSort(string name[], int elems)
{
int startScan, minIndex;
string strName;
for(startScan = 0; startScan < (elems - 1); startScan++)
{
minIndex = startScan;
strName = name[startScan];
for(int index = startScan + 1; index < elems; index++)
{
if(name[index] < strName)
{
strName = name[index];
minIndex = index;
}
}
name[minIndex] = name[startScan];
name[startScan] = strName;
}
}


void showArray(string name[], int elems)
{
for(int count = 0; count < elems; count++)
cout << count << ": " << name[count] << endl;
}
Please put your code in Code tags.
http://www.cplusplus.com/articles/jEywvCM9/

What is not working ?
Topic archived. No new replies allowed.