title: FlatBuffers: Write to and read from binary file?
body: <p>I have basic knowledge of file streams in C++ and Google <a href="http://google.github.io/flatbuffers/" rel="noreferrer">FlatBuffers</a>. The Schema file is quite simple, also creating a buffer and reading
  from a buffer pointer. The thing that I don't get is how to save multiple buffers into a binary file, and then read that binary file to
  get any random buffer.</p>
  
  <p>Here is a simple Schema with two arrays of floats:</p>
  
  <pre><code>table Car {
      field_a:[float];
      field_b:[float];
  }
  </code></pre>
  
  <p>.</p>
  
  <p>A function for building the buffer (although without the file saving):</p>
  
  <pre><code>bool save_flatbuf(string file_path, vector&lt;double&gt; vec_a, vector&lt;double&gt; vec_b) {
      flatbuffers::FlatBufferBuilder builder;
  
      auto vec_floats_a = builder.CreateVector(vec_a, vec_a.size());
      auto vec_floats_b = builder.CreateVector(vec_b, vec_b.size());
  
      auto mloc = CreateCar(builder, &amp;vec_floats_a, &amp;vec_floats_b);
  
      builder.Finish(mloc);
  
      // How to save it into a binary file with a list of "Cars"?
  }
  </code></pre>
  
  <p>.</p>
  
  <p>And a function for reading the buffer after it was read from the binary file (without the file reading):</p>
  
  <pre><code>bool read_flatbuf(string file_path) {
  
      // How to get the buffer pointer to a "Car" from a binary file with a "list of Cars" ? .
  
      vector&lt;double&gt; final_vec_a;
      vector&lt;double&gt; final_vec_b;
  
      auto car = GetCar(buffer_pointer);
  
      auto fa = car-&gt;field_a();
      auto fb = car-&gt;field_b();
  
      final_vec_a.resize(fa-&gt;size());
      for (int i = 0; i &lt; fa-&gt;size(); i++) {
          final_vec_a[i] = fa-&gt;Get(i);
      }
  
      final_vec_b.resize(fb-&gt;size());
      for (int i = 0; i &lt; fb-&gt;size(); i++) {
          final_vec_b[i] = fb-&gt;Get(i);
      }
  }
  </code></pre>
  
  <p>Not sure if the way to access the buffer's info is correct. For instance the way to get the length of the array fields.</p>
  
  <p>Code examples for file interaction (write/read multiple buffers in one file) would be welcome.</p>