title: Why can't I read and append with std::fstream on Mac OS X?
body: <p>Consider the following C++ program, which takes a file and prints each line. It's a slice of a larger program where I later append to the file, based on what I see.</p>
  
  <pre><code>#include &lt;fstream&gt;
  using std::fstream;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using std::string;
  
  int main()
  {
   fstream file("file.txt", fstream::in | fstream::out | fstream::app);
  
   string line;
   while (std::getline(file, line))
    std::cerr &lt;&lt; line &lt;&lt; std::endl;
  
   return 0;
  }
  </code></pre>
  
  <p>Now apply this version of <code>file.txt</code> (One word on the first line, followed by a newline):</p>
  
  <pre><code>Rain
  </code></pre>
  
  <p>On my machine (Snow Leopard), this prints out nothing. On closer inspection, the first call to getline fails. Strangely, it also fails if I add a second line: still nothing is printed!</p>
  
  <p>Can anyone solve this mystery?</p>