title: Creating a global FILE* object?
body: <p>I'm building a program that has several functions that need to read data from a file. Since the functions are used fairly frequently, opening and closing the file for each call would be too time consuming, so my plan was to make the FILE* object global, and have the file open the whole duration of the program. Apparently, though, it's not possible, since this:</p>
  
  <pre><code>#include &lt;fstream&gt;
  FILE * yhtit;
  yhtit = fopen("thefile.txt","r");
  int main() {
  return 0; }
  </code></pre>
  
  <p>gives error: <code>main.cpp|54|error: expected constructor, destructor, or type conversion before ‘=’ token|</code></p>
  
  <p>What's the best way to keep a file open the whole duration of the program, without having to separately pass the FILE* object to every function that needs it?</p>