This seems easy, but apparently I've overlooked something.
What I'm trying to do is this:
1. I have to read the contents of a *.dat file (in this case the file contains 12 names, each on its own line right after one another)
2. Use a bubble sort routine to put the names in ascending order
3. display the sorted files to the screen
The bubble sort is not a problem if I could get these strings into an array. Then I would use string class method swap to do the rest.
I'm runnning into problems when I try populating the string array. I'm not getting compiler errors, but when I test outputing the array I get nothing. I've written stuff before using character arrays to do the same thing, but I can't do this here. I've looked in this forum and elseware but nothing I've found difinitively explains how a string array works. My text book has nothing on this, either, nor was this ever discussed in my class. I've tried double scripted arrays, but that didn't work either. Please help...This will be on my Monday's exam. This is NOT a homework assignment.
Thanks in advance,
ifstream inFile("strings.dat", ios::in); //declare ifstream object
string stringInput; //string variable placeholder
string sArray; //string array to hold 30 strings
inFile.clear(); //clear EOF
inFile.seekg(0); //start reading at beginning of file
while (inFile >> stringInput)
sArray[element] = stringInput;
cout << "stringInput = " << stringInput << endl; //testing output... Nothing displays here????
cout << "sArray = "<< sArray[element] << endl; //testing output... Nothing displays here, either
cout << sArray << endl //more testing
<< sArray <<endl; //more testing