title: Write a float with full precision in C++
body: <p>In C++, can I write and read back a float (or double) in text format without losing precision?</p>
  
  <p>Consider the following:</p>
  
  <pre><code>float f = ...;
  {
      std::ofstream fout("file.txt");
      // Set some flags on fout
      fout &lt;&lt; f;
   }
   float f_read;
   {
       std::ifstream fin("file.txt");
       fin &gt;&gt; f;
    }
    if (f != f_read) {
        std::cout &lt;&lt; "precision lost" &lt;&lt; std::endl;
    }
  </code></pre>
  
  <p>I understand why precision is lost sometimes. However, if I print the value with enough digits, I should be able to read back the exact same value.</p>
  
  <p>Is there a given set of flags that is guaranteed to never lose precision?
  Would this behaviour be portable across platforms?</p>