title: ifstream variable in class
body: <p>I have my class which has to have ifstream file in it.</p>
  
  <p>I dont know how to present it in the class header</p>
  
  <p>A:</p>
  
  <pre><code>class MyClass
  {
      ...
      ifstream file;
      ...
  }
  </code></pre>
  
  <p>B:</p>
  
  <pre><code>class MyClass
  {
      ...
      ifstream&amp; file;
      ...
  }
  </code></pre>
  
  <p>I know that ifstream has to get path in the decaleration, so how do I do it?</p>
  
  <p>Also how do I open a file with it?</p>
  
  <p>EDIT:</p>
  
  <p>I want the first way, but how do I use it SYNTAX-ly?</p>
  
  <p>let's say this is the header(part of it)</p>
  
  <pre><code>class MyClass
  {
      string path;
      ifstream file;
  public:
      MyClass();
      void read_from_file();
      bool is_file_open();
      ...
  </code></pre>
  
  <p>}</p>
  
  <p>funcs</p>
  
  <pre><code>void MyClass::read_from_file()
  {
      //what do I do to open it???
      this-&gt;file.open(this-&gt;path); //Maybe, IDK
      ... // ?
  }
  </code></pre>