I am trying to make a program that stores a database of employees and stores them in an external file. the function that reads a vector from the .dat file and loads it into the program reads the file but whenever I try to display or modify the loaded vector the program crashes.
//displays vector void Database:: displayAll() const { for(std::vector<Employee>::const_iterator iter = mEmployees.begin(); iter != mEmployees.end(); ++iter) { iter -> display(); } } std::vector<Employee> mEmployees; void Database::readData() { ifstream empIn("employee.dat" , ios::binary); empIn.seekg(0,ifstream::end); long size2 = empIn.tellg(); empIn.seekg(0,ifstream::beg); mEmployees.resize(size2); empIn.read((char*)&mEmployees, size2); empIn.close(); cout << mEmployees.size() << endl; //this tests whether or not it reads. }