title: Why is getline() in C++ not working? (no matching function for call to 'getline(std::ofstream&, std::string&)'
body: <p>I'm trying to read from a file, but C++ is not wanting to run <code>getline()</code>.</p>
  
  <p>I get this error: </p>
  
  <pre><code>C:\main.cpp:18: error: no matching function for call to 'getline(std::ofstream&amp;, std::string&amp;)'
            std::getline (file,line);
                                   ^
  </code></pre>
  
  <p>This is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main(){
      string line;
  
      std::ofstream file;
      file.open("test.txt");
      if (file.is_open())
       {
         while ( file.good() )
         {
           getline (file,line);
           cout &lt;&lt; line &lt;&lt; endl;
         }
         file.close();
       }
  
  
  }
  </code></pre>