Hey guys, I am having a c++ problem and i cant find any info on how to solve it.
I am nearly finished my last c++ assignement and the problem i am having is successfully saving and opening a file.
I have to make a student database. What i have done is create vector of structures.
I need to know how to save a vector to a binary file and then retrieve it again. The code i have used compiles but the program crashes when i try to do anything with it after opening it again, probably because the size of the vector wasn't found properly.
I am writing to the file like this:
file.read(reinterpret_cast<char *>(&(students)),sizeof(students));
where students is the vector in question
I am reading from the file like this:
file.read(reinterpret_cast<char *>(&(students)),sizeof(students));
I have an integer which i read in before reading the vector and write before writing the vector which i am able to do successfully.
Thanks,
Greg
I am nearly finished my last c++ assignement and the problem i am having is successfully saving and opening a file.
I have to make a student database. What i have done is create vector of structures.
I need to know how to save a vector to a binary file and then retrieve it again. The code i have used compiles but the program crashes when i try to do anything with it after opening it again, probably because the size of the vector wasn't found properly.
I am writing to the file like this:
file.read(reinterpret_cast<char *>(&(students)),sizeof(students));
where students is the vector in question
I am reading from the file like this:
file.read(reinterpret_cast<char *>(&(students)),sizeof(students));
I have an integer which i read in before reading the vector and write before writing the vector which i am able to do successfully.
Thanks,
Greg