title: Inheriting from ifstream
body: <p>Can I inherit from ifstream and read the file from my derived class like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  const string usage_str = "Usage: extract &lt;file&gt;";
  
  class File: public ifstream
  {
  public:
      explicit File(const char *fname, openmode mode = in);
      void extract(ostream&amp; o);
  };
  
  File::File(const char *fname, openmode mode)
  {
      ifstream(fname, mode);
  }
  
  void File::extract(ostream&amp; o)
  {
      char ch;
      char buf[512];
      int i = 0;
  
      while (good()) {
          getline(buf, sizeof(buf));
          o&lt;&lt;buf;
          i++;
      }   
      cout&lt;&lt;"Done "&lt;&lt;i&lt;&lt;" times"&lt;&lt;endl;
  }
  
  void msg_exit(ostream&amp; o, const string&amp; msg, int exit_code)
  {
      o&lt;&lt;msg&lt;&lt;endl;
      exit(exit_code);
  }
  
  int do_extract(int argc, char *argv[])
  {
      cout&lt;&lt;"Opening "&lt;&lt;argv[1]&lt;&lt;endl;
      File f(argv[1]);
      if (! f)
          msg_exit(cerr, usage_str, 1);
      f.extract(cout);
      return 0;
  }
  
  int main(int argc, char *argv[])
  {
      if (argc &lt; 2)
          msg_exit(cout, usage_str, 0);
  
      do_extract(argc, argv);
      return 0;
  }
  </code></pre>
  
  <p>I expect it to read the whole file, but it reads just one symbol (which is not the first symbol of the given file)...</p>