Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ -- reading dynamically allocated vectors from a binary file
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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. </p> <p>tl;dr -- How do I read a variable-size vector of variable-length strings from a binary file?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload