Best practices when reading from and to a file into a vector

I have a small console program that keeps track of a collection of different items ("entities"), allowing the user to view some listings of items, add items, modify items, delete items.
For now, the program only stores items in memory, in vectors of structs. Now I'm trying to make a few modifications to save the items in text files to add some very basic persistence.
So far I decided I'm going to make a different text file for each entity (that is, for each struct). And then, every time I need to perform some action (add, modify, delete, list items) I'll load the items from the file into a vector of structs, do whatever I need in memory and then save back to the file if any modification has been made.

1* My first question would be if that's a correct approach.

And then I'd like to know how to handle vector creation and file I/O:

2* My main function shows a menu from where the user picks what to do. Should I declare all the vectors there so they're kept throughout the program execution? In that case, I'd pass the needed vectors to each function every time it's called. The other option I'm considering is to declare the needed vector as local to the function, instead of passing it from the menu.

3* When is the best time to read from files? In case I declare the vectors local to main(), should I read all the files as soon as the program starts and load all the info in the vectors? Or should I read at the beginning of each function that is called from the menu?

4* And when is the best time to write into the files? Should I write back to a file whenever a function that modified items returns?

Thanks!
Topic archived. No new replies allowed.