Saving a vector to a file

Another C++ question, please do notify me if this forum is C-only!
:slight_smile:

I'm having a vector...

vector<Person> x;

... with a class I've defined (Person).

I have several elements in this vector and I would like to save it to a file (binary (?)). And later on open up this file to retrieve the elements in the vector.

Any suggestions on how to accomplish this?

First write the value of vector::size() to the file. And then write all the values in vector using a for-loop. The size will tell you (when reading from the file) how many vector values are present.