title: Using fstream Object as a Function Parameter
body: <pre><code>#include &lt;iostream.h&gt;
  #include &lt;fstream.h&gt;
  #include &lt;stdlib.h&gt;
  
  void vowel(fstream a){
      char ch;
      int ctr = 0;
      while(!a.eof()){
          a.get(ch);
          if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
              cout &lt;&lt; ch;
              ctr++;
          }
      }
      cout &lt;&lt; "Number of Vowels: " &lt;&lt; ctr;
  }
  
  main(){
      fstream a;
      a.open("temp.txt", ios::in);
      vowel(a);
  return 0;
  }
  </code></pre>
  
  <p>In this simple program , I am trying t count the number of caps Vowels in the file temp.txt. However, I am getting the error:</p>
  
  <blockquote>
    <p>ios::ios(ios &amp;) is not accessible in function
    fstream::fstream(fstream&amp;)</p>
  </blockquote>
  
  <p>Instead opening the file in the function itself does the job.
  Why is it so? 
  Thanks a lot</p>
  
  <p>NB: </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/13231730/how-do-i-use-fstream-specifically-ofstream-through-a-functions-parameters">How do I use fstream (specifically ofstream) through a functions parameters</a></p>
  </blockquote>
  
  <p>Here it says, that it should work the way I am trying.</p>
  
  <p>Rick</p>