I am working on a problem, and I am not sure if I'm doing this properly, or if I even have the right approach at all. My code, so far, just gives me segfaults.
I have a simple little receipt writing program to practice some C++ concepts, one of them being file i/o in binary. I have a couple arrays holding data (one holding strings of a service type, the other holding corresponding double costs). I have a little menu, and the writing in binary part goes fine. However, I am not sure how to read these back from the file.
I am currently using a structure to hold various data members (customer's name, total charges, etc.), and I want to write all of the services they chose, along with their corresponding prices, to a file, and then be able to read them back. These are currently stored in vectors in the structure.
I think I understand how to read/write strings to/from a binary file (write the length of the string, then the data, then read the length back, then read that many bytes into a string). But how do I do this with a vector? I understand how it can be done with, say, a vector of fixed-size members (i.e. ints), but what about a vector of strings? In this case, the members do not have a set size, so I am not sure how to read them back.
Is this even possible? If anyone could point me in the right direction, that would be extremely helpful. There was a similar forum posting a year or so ago, but it didn't help me much.
tl;dr -- How do I read a variable-size vector of variable-length strings from a binary file?