title: How to write strings as binaries to file?
body: <p>This is a C++ question. I have a class that contains a string:</p>
  
  <pre><code>class MyClass{
  public:
  std::string s;
  };
  </code></pre>
  
  <p>And I have an array of MyClass objects:</p>
  
  <pre><code>MyClass * array = MyClass[3];
  </code></pre>
  
  <p>Now I want to write the array as binaries into a file. I cannot use:</p>
  
  <pre><code>Ofstream.write((char *)array, 3 * sizeof(MyClass))
  </code></pre>
  
  <p>because the size of MyClass varies.</p>
  
  <p>How can I use Ofstream.write to achieve the purpose? Many thanks.</p>