C++ file reading issue[solved]

So for my homework I have to write some C++ code, it reads from a file lets you modify data and right to file. However the output results seem weird , if I write a single piece of data store it then read it I get back 3 results , 2 in the first group and 1 in the second.


#include "fileh.h"
using namespace std;//create the variables used in the program
fstream filestream;
student_info temp_data;//even though its temporary its used a lot , more efficient than using multiple local declerations
void write_to_class(student_info data, int classnum){//create a function that writes to the main class data
	if (classnum == 1){//check the class numbers
		class1.push_back(data);//if the number is the one selected
	}
	else if (classnum == 2){
		class2.push_back(data);
	}
	else if (classnum == 3){
		class3.push_back(data);
	}
	else{//if all values dont work then call this
		cout << "Invalid class number!" << endl;
		return;
	}
}
bool write_to_file(){//function that writes data to a saved binary file
	int classcurrent = 1;//variable for detecting class during iteration
	vector<student_info>::iterator start;//create two iterators for the start and end positions of the class lists
	vector<student_info>::iterator end;
	while (classcurrent < 3){
		if (classcurrent == 1){//by using selection within a while loop makes the code cleaner , it also means there is less repetition with the code
			filestream.open("class1.bin", ios::out | ios::binary | ios::trunc);//open the file for writing in a binary format trunc means all prior
			//data is deleted
			start = class1.begin();//set the iterators for the positions within the vector we are reading from
			end = class1.end();
		}
		else if (classcurrent == 2){//repeat for other classes
			filestream.open("class2.bin", ios::out | ios::binary | ios::trunc);
			start = class2.begin();
			end = class2.end();
		}
		else{
			filestream.open("class3.bin", ios::out | ios::binary | ios::trunc);
			start = class3.begin();
			end = class3.end();
		}

		if (filestream.is_open()){//check to see if there is no error with the file
			for (vector<student_info>::iterator position = start; position != end; position++){
				temp_data = *position;
				filestream.write((char *)(&temp_data), sizeof(student_info));
			}

		}
		else{
			return false;//if there is immediately cancel the operation and notify the calling function with a boolean
		}
		filestream.close();//close the filestream to save the operaions
		classcurrent += 1;//increase the current class to modify how the selection occurs
	}
	return true;//if nothing bad has occured then tell the calling function its completed
}
bool read_from_file(){//this function reads from a file and notifys the calling function the status afterward
	int classcurrent = 1;//same as the write function 
	while (classcurrent <3){
		if (classcurrent == 1){

			filestream.open("class1.bin", ios::in | ios::binary);//open the file for reading in binary

		}
		else if (classcurrent == 2){
			filestream.open("class2.bin", ios::in | ios::binary);
		}

		else{
			filestream.open("class3.bin", ios::in | ios::binary);
		}
		if (filestream.is_open()){//check if the file has been successfully opened

			while (true){
				if (filestream.eof() == 1){//if the end of the file has been read then there is no point continuing reading the data
					classcurrent += 1;
					break;
				}

				filestream.read((char *)(&temp_data), sizeof(student_info));//if there is still stuff to read then read the data
				write_to_class(temp_data, classcurrent);//copy this data into the main class data
			}
		}
		else{
			return false;
			//this allows for returning an error to the user if anything failed during this operation.
		}
		filestream.close();//close the filestream to save what happened
		
	}

	return true;
}

Help would be greatly appreciated.