title: Error overloading >> Operator reading from file into class
body: <p>I am currently working on a program for class that requires me to overload the stream extraction operator, >>, to take data from a file straight into a class. I am getting a:</p>
  
  <p><em>error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::ifstream' (or there is no acceptable conversion)</em></p>
  
  <p>Here is the specific code the error is affecting.</p>
  
  <p><strong>int main()</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include "stockType.h"
  #include "stockListType.h"
  
  using namespace std;
  
  stockType myStock;
  stockListType stockList;
  ifstream infile;
  infile.open("StockData.txt");
  
  infile &gt;&gt; myStock;
  </code></pre>
  
  <p><strong>stockType.h Header File</strong></p>
  
  <pre><code>#ifndef STOCKTYPE_H
  #define STOCKTYPE_H
  
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  
  class stockType
  {
  public:
      stockType();
      void printStock();
      void calcPercent();
  
  
  
      char Symbol[3];
      float openingPrice;
      float closingPrice;
      float todayHigh;
      float todayLow;
      float prevClose;
      int volume;
      float percent;
  
      friend std::ifstream &amp;operator &gt;&gt; (std::ifstream &amp;in, const stockType &amp;myStock);
  };
  
  #endif
  </code></pre>
  
  <p><strong>stockType.cpp Resource File</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include "stockType.h"
  
  std::ifstream&amp; operator&gt;&gt; (std::ifstream &amp;in, const stockType &amp;myStock)
  {
  in &gt;&gt; myStock.Symbol;
  in &gt;&gt; myStock.openingPrice;
  in &gt;&gt; myStock.closingPrice;
  in &gt;&gt; myStock.todayHigh;
  in &gt;&gt; myStock.todayLow;
  in &gt;&gt; myStock.prevClose;
  in &gt;&gt; myStock.volume;
  
  return in;
  }
  </code></pre>
  
  <p>most of the searching I have done is people having problems using ostream to do this and are getting their data during program use. Trying to erorr-correct using the ifstream and reading straight from a txt file has been difficult. I can provide whatever additional information is needed. Any help is much appreciated. thanks.</p>