title: no operator matches these operands ofstream >> string
body: <p>Trying to count the number of similar items in the text file after writing the text but i am getting an <code>No operator &lt;&lt; matches these operands operand type are std::ofstream &gt;&gt; std::string</code> . Code works but when adding the while loop is where i get the error  <code>textfile &gt;&gt; item</code>. Does it have anything to do with ofstream of the textfile?</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  int main()
  {
  
      string accord[6];
  
      ofstream textfile;
      textfile.open("C:\\temp\\1.txt");
  
      cout &lt;&lt; "Enter a 6 cylinder car : " &lt;&lt; endl;
  
      for (int x = 0; x &lt; 6; x++) {
          getline(cin, accord[x]);
      }
      for (int x = 0; x &lt; 6; x++) {
  
          textfile &lt;&lt; accord[x] &lt;&lt; endl;
      }
      int count = 0;
      string item;
      while (!textfile.eof()) {
          textfile &gt;&gt; item;
          if (item == "6") {
              count++;
          }
      }
  
      cout &lt;&lt; count &lt;&lt; "found!" &lt;&lt; endl;
  
  
  
      textfile.close();
      return 0;
  }
  </code></pre>