Q:

how to sort a vector in the order it is read from file with structures

I have a structure  with names and grades inside, I will use a vector which is meant to read the inside of a file till the end with the structure.  For example: 
 struct ReadAll{string name; double numbers;}

 vector <ReadAll>userInfo;

i need to display the results in a file so far everything works but i need to display them as ex: student1 89 47 99.... student4 89 78 45.. but all i get is student4 98 78 45 ... student1 89 47 99..   how can i display them in the right order? 
void writeStudents(vector<Student>& students, string outputFileName)    
{//students.push_back(Student());

ofstream outputFile;
outputFile.open(outputFileName.c_str()); 
while(students.size() ! = 0) 
{

   for (int count = students.size(); count > 0; --count)
   {  
      students.back().average = (students.back().grade1 + 
      students.back().grade2 + students.back().grade3) / 3; 
      outputFile << "size is: "<< students.size() <<endl;
      outputFile << students.back().name <<endl;
      outputFile << students.back().grade1 <<endl;
      outputFile << students.back().grade2 <<endl;
      outputFile << students.back().grade3 <<endl;
      outputFile << "Average: " << students.back().average <<endl;
      students.pop_back();
      //count++;
   }
 }

}
As it is now I just dont see what I have to do.                                                                                    

A:

Is there anything wrong with the easy way of doing things?  Something like this
for (int i = 0; i < students.size(); ++i)
{
    outputFile << students[i].name <<endl;
    outputFile << students[i].grade1 <<endl;
    outputFile << students[i].grade2 <<endl;
    outputFile << students[i].grade3 <<endl;
}

I don't understand why you are going backwards through the vector and removing items as you print them.  That's a bit strange.