title: How do I open a file in main and then read from the file in another function?
body: <p>In my main function I want to open a txt file while not hard-coding the file name, then call another function to read from the txt file.</p>
  <p>I've tried to pass it as an argument according to another question thread, but it's solutions don't seem to work for me. <a href="https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons">The thread I looked at.</a></p>
  <p>Sorry if this is an obvious question, I'm quite new to this so more in depth explanations are welcome.</p>
  <p>Here's the code</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cmath&gt;
  using namespace std;
  
  int readfile(double &amp;a, double &amp;b, double &amp;c, ifstream filein)
  {
      filein &gt;&gt; a &gt;&gt; b &gt;&gt; c;
      cout &lt;&lt; a &lt;&lt; b &lt;&lt; c;
  }
  
  int main()
  {
      double a, b, c;
      bool loop;
      
  
      string infilename;
      cout &lt;&lt; &quot;Enter the input filename to open\n&quot;;
      cin &gt;&gt; infilename;
  
  
      ifstream filein;
      
  
      filein.open(infilename);
     
  
      if (!filein)
      {
          cout &lt;&lt; &quot;Input file could not be opened&quot;;
          return 1;
      }
      else
      {
          loop = true;
  
      }
      
  
  
      while (loop == true )
      {
          readfile(a, b, c, filein);
      }
  }
  </code></pre>
  <p>Here's the error message I'm getting
  stackoverflow.cpp|42|error: use of deleted function 'std::basic_ifstream&lt;_CharT, _Traits&gt;::basic_ifstream(const std::basic_ifstream&lt;_CharT, _Traits&gt;&amp;) [with _CharT = char; _Traits = std::char_traits]'|</p>