I am currently using below program to write one object of class student inside a file and than read it but as i try to save more than one object than read it the output is not correct:
To read an object:
Here i have created two vectors which contains two objects. Any other way in which i can save more than one object inside a file is ok for me. To read a file :
I get segmentation fault when i do this. Is their any way in which i can save group of objects either of class or struct inside a file and than again read it like above.
Maybe like this - store the size, and then the data. In a vector, the elements are stored in consecutive memory locations so this should be ok. There might be safer ways to approach this.