Sorry if this is too newb, but no one in beginner responded to me so ill try here.
I am suppose to make a program that reads in data from a text file (integers only) and sorts them as it inserts them into an array of size 10. I did this using an insertion sort, which worked great. But now I am being told that I need the function has to read ALL of the numbers in the text file, not just the first 10, and I am not allowed to store them THEN sort, it has to be sorted as being stored. I cannot figure out how to do this, Any help would be appreciated.
void sortArray(int iArray[])
{
string fileName = "";
fstream inFile;
int tmp = 0;
int size = 10;
//Prompt user to input the name of the file
cout << "please enter file name: ";
cin >> fileName;
//Open file
inFile.open(fileName);
int j = 0;
//Insertion sort, compares data as its read to the array and swaps numbers if needed
for (int i = 0; i < size; i++)
{
inFile >> tmp;
iArray[i] = tmp;
j = i;
while (j > 0 && iArray[j-1] > iArray[j])
{
swap(iArray[j], iArray[j-1]);
j--;
}
}
inFile.close();
}