title: How to quickly write large amounts of data into txt files
body: <p>Recently I was trying to write pointcloud data to .txt file by using C++ in Visual Studio 2010. At the beginning I used ostream to output the data, but I found it slow when writing the data.</p>
  
  <p>My code :</p>
  
  <pre><code>std::ofstream outfile;
  outfile.open(filename.c_str());
  for(int index = 0;index &lt; pointcloud.size();index++){
    outfile&lt;&lt;pointcloud[index].x&lt;&lt;pointcloud[index].y&lt;&lt;pointcloud[index].z
    &lt;&lt;pointcloud[index].r&lt;&lt;pointcloud[index].g&lt;&lt;pointcloud[index].b&lt;&lt;'\n';
  }
  outfile&lt;&lt;std::endl;
  </code></pre>
  
  <p>The output pointcloud is very huge, almost 0.5G. It takes minutes to write into .txt file. How can I improve the speed of writing down the data? I thought it might be the problem of the size of cache buffer, but not sure. Can someone help me with this?  </p>