title: how to read and write non-fixed-length structs to biniary file c++
body: <p>I have vector of structs:</p>
  <pre><code>typedef struct
  {
      uint64_t id = 0;
      std::string name;
      std::vector&lt;uint64_t&gt; data;
  } entry;
  </code></pre>
  <p>That I want to write to file:</p>
  <pre><code>FILE *testFile = nullptr;
  testFile = fopen(&quot;test.b&quot;, &quot;wb&quot;);
  </code></pre>
  <p>However the normal method for read/write</p>
  <pre><code>fwrite(vector.data(), sizeof vector[0], vector.size(), testFile);
  fread(vector.data(), sizeof(entry), numberOfEntries, testFile);
  </code></pre>
  <p>does not work as the size of entry can vary wildly depending on the contents of</p>
  <pre><code>std::string name;
  std::vector&lt;uint64_t&gt; data;
  </code></pre>
  <p>so I would like methods and pointers about how to do read/writing of this data to/from files.</p>