title: Reading file until blank line
body: <p>After reading <a href="https://stackoverflow.com/users/179910/jerry-coffin">Jerry Coffin</a>'s answer on this <a href="https://stackoverflow.com/questions/4409446/reading-until-user-enters-blank-line/4409554#4409554">question</a> I copy-pasted his code into my editor, and after some minor edits it compiled and run like it should.</p>
  
  <p>Here is the code after the changes:</p>
  
  <pre><code> #include &lt;iostream&gt;
   #include &lt;string&gt;
   #include &lt;istream&gt;
   #include &lt;fstream&gt;
  
  class non_blank {
  private:
   std::string data_;
  
   friend std::istream&amp; operator&gt;&gt; (std::istream &amp;is, non_blank &amp;n) {
    std::getline(is, n.data_);
  
    if (n.data_.length() == 0) {
     is.setstate(std::ios::failbit);
    }
    return is;
   }
  
  public:
   operator std::string() const {
    return data_;
   }
  };
  
  
  int main(int, char *[]) {
  
   non_blank line;
   std::ifstream ifs("teste.txt");
  
   while(ifs &gt;&gt; line) {
    //std::cout &lt;&lt; line; &lt;----- error
    std::string s = line;
    std::cout &lt;&lt; s &lt;&lt; std::endl;
   }
  
   return 0;
  }
  </code></pre>
  
  <ul>
  <li><p>I've got an error when trying to use a non_blank variable in a <code>std::cout &lt;&lt;...</code> expression. Shouldn't I be able to use a variable of the type non_blank anywhere I would use a std::string? Isn't it the purpose of the cast/conversion operator?? <a href="https://stackoverflow.com/questions/3044690/operator-stdstring-const/3044700#3044700">answer</a></p></li>
  <li><p>Why can't I access the private variable <code>string::data_</code> directly in the definition of the <code>operator &gt;&gt;</code>? </p></li>
  </ul>
  
  <p>Here is the error I got:</p>
  
  <pre><code>..\main.cpp: In function `std::istream&amp; operator&gt;&gt;(std::istream&amp;, non_blank&amp;)':
  ..\main.cpp:21: error: invalid use of non-static data member `non_blank::data_'
  ..\main.cpp:26: error: from this location
  </code></pre>