title: Output a ostringstream to file
body: <p>I currently do this to write the contents of an <code>ostringstream</code> to a file:</p>
  
  <pre><code>... // -- Loop 1 Start
  
  std::ostringstream osStr;
  
  ... // -- Loop 2 Start
  
      cv::string s(osStr.str());
      std::istringstream iss(s);
      cv::vector&lt;cv::string&gt; subVec;
      do{
          cv::string sub;
          iss &gt;&gt; sub;
          subVec.push_back(sub);
      } while (iss);
  
      cv::FileStorage fs("subVec.txt", cv::FileStorage::WRITE);
      fs &lt;&lt; "subVec" &lt;&lt; subVec;
      fs.release();
  
  ... // -- Loop 2 End
  
  ... // -- Loop 1 End
  </code></pre>
  
  <p>but this overwrites what was previously in the file.</p>
  
  <p>So I moved the <code>cv::FileStorage fs("subVec.txt", cv::FileStorage::WRITE);</code> to before the loop, and <code>fs.release</code> to after the loop.</p>
  
  <pre><code>cv::FileStorage fs("subVec.txt", cv::FileStorage::WRITE);
  
  ... // -- Loop 1 Start
  
  std::ostringstream osStr;
  
  ... // -- Loop 2 Start
  
      cv::string s(osStr.str());
      std::istringstream iss(s);
      cv::vector&lt;cv::string&gt; subVec;
      do{
          cv::string sub;
          iss &gt;&gt; sub;
          subVec.push_back(sub);
      } while (iss);
  
      fs &lt;&lt; "subVec" &lt;&lt; subVec;
  
  ... // -- Loop 2 End
  
  ... // -- Loop 1 End
  
  fs.release();
  </code></pre>
  
  <p>This worked in a way as it did continuously write to the <code>.txt</code>, but was unusable due to Duplicated Keys:</p>
  
  <pre><code>%YAML:1.0
  subVec:
     - "1"
     - "2"
  ...
     - "33"
     - "34"
  subVec:
     - "1"
     - "3"
  ...
     - "30"
     - "31"
  </code></pre>
  
  <p><strong>See how <em>subVec</em> is repeated</strong></p>
  
  <p>I'm looking for a way to save the contents of the <code>ostringstream</code> to a file where it doesn't overwrite the contents each time, but is actually readable.</p>
  
  <p><strong>OpenCV Error: Parsing error (subVec.txt(27): Duplicated key) in cvGetFileNode</strong></p>