title: terminate called after throwing an instance of 'std::runtime_error' what(): I/O error with filebuf & ostream
body: <p>I am trying to serialize several text files and I have a function like this:</p>
  
  <pre><code>void to_file_px(Ciphertext* encryptedPx, int index) {
      // Serialize Pixel i
  
      //red
      filebuf* fbCipherR; // EDIT: THIS LINE IS PROBLEMATIC
      string* filenameR = new string("../serialization/pixels/px" + to_string(index) + "R.txt");
      fbCipherR -&gt; open((*filenameR).c_str(), std::ios::out|std::ios::binary);
      ostream* osCipherR = new ostream(fbCipherR);
      encryptedPx[0].Ciphertext::save((*osCipherR));
      fbCipherR -&gt; close();
      delete filenameR;
      delete fbCipherR;
      delete osCipherR;
  
      //green
  
      //blue
  
      delete[] encryptedPx;
  }
  </code></pre>
  
  <p>However, this function causes an error as <code>Segmentation fault (core dumped)</code>.</p>
  
  <p>May I know what exactly causes the error?</p>
  
  <p>Note: <code>Ciphertext::save</code> comes from Microsoft SEAL</p>
  
  <hr>
  
  <p>OK, I made a mistake. I didn't initialize <code>filebuf*</code>.</p>
  
  <p>So I changed <code>filebuf* fbCipherR = new filebuf();</code> and I got a new error message:</p>
  
  <pre><code>terminate called after throwing an instance of 'std::runtime_error'
    what():  I/O error
  Aborted (core dumped)
  </code></pre>