title: Pointer to an fstream issue with >> operator?
body: <p>I'm trying to use file streams to read input and I need to be able to maintain a pointer to a file when I transfer it in between classes. Here is a rough outline of what I'm trying to do:</p>
  
  <pre><code>class A {
  friend class B;
  public:
      void somefunction();
  
  private:
      fstream o;
      B b;
  };
  
  class B {
     fstream * in;
  
     public:
          void input();
          void modify(fstream *);
  };
  </code></pre>
  
  <p>Here is a simple representation of the two classes I'm trying to work with. I have a function that modifies the fstream like so:</p>
  
  <pre><code>void A::somefunction() {
      B.modify(o);
  }
  
  void B::modify(fstream * o) {
       this -&gt; in = o;
  }
  </code></pre>
  
  <p>Here I pass the other fstream so that the class B now maintains a pointer to that file. However, when I try to read input using it, I fail:</p>
  
  <pre><code>void B::input() {
      while (*in &gt;&gt; object) {
          cout &lt;&lt; object &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>The statement simply evaluates to false and the while loop does not execute. I'm wondering if it is an issue with the streams, but I'm not sure. Does anyone have any suggestions?</p>
  
  <p>EDIT:</p>
  
  <pre><code>B b;
  b.modify(o);
  </code></pre>
  
  <p>I want to pass in the <code>fstream o</code> from class A into class B. I set the <code>fstream * in</code> in class A to the <code>fstream o</code> in class B. I forgot to add that fstream o is reading from a file, and I would like to essentially "transfer" the stream to class B so that it may read from the file.</p>