title: Why do I get a "no matching function" error when I open an fstream with the file name in a std::string?
body: <p>I am trying to write a program that reads in a list of strings from a file and checks what strings are missing from a second file and prints them to the screen. However, I am currently getting an error when I try to compile. Below is the error I am getting when I try to compile as well as the code. Thank you for the help</p>
  <p>This is the code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  ifstream IN_FILE;
  ofstream OUT_FILE;
  
  int main()  { 
      int k = 0;
      int m = 0;
      int n = 0;
      string a[5000];
      string b[5000];
      string filename;
      bool good;
  
      //open file and check if valid entry
      cout &lt;&lt; &quot;\n\nWhat is the name of the first file (ex: filename.txt)\n&quot; &lt;&lt; endl &lt;&lt; &quot;FILENAME: &quot;;
      getline(cin, filename);
      IN_FILE.open(filename);
      while(!IN_FILE) {
          cout &lt;&lt; &quot;Sorry the file you entered could not be opened\n&quot;;
          cout &lt;&lt; &quot;\n\nWhat is the name of the first file (ex: filename.txt)\n&quot; &lt;&lt; endl &lt;&lt; &quot;FILENAME: &quot;;
          getline(cin, filename);
          IN_FILE.open(filename);
      }
  
      //Read every line from file
      while(!IN_FILE.eof()) {
          getline(IN_FILE, a[k]);
          k++;
      }
      n = k;
      k = 0;
      IN_FILE.close();
  
      //open file and check if valid entry
      cout &lt;&lt; &quot;\n\nWhat is the name of the first file (ex: filename.txt)\n&quot; &lt;&lt; endl &lt;&lt; &quot;FILENAME: &quot;;
      getline(cin, filename);
      IN_FILE.open(filename);
      while(!IN_FILE) {
          cout &lt;&lt; &quot;Sorry the file you entered could not be opened\n&quot;;
          cout &lt;&lt; &quot;\n\nWhat is the name of the first file (ex: filename.txt)\n&quot; &lt;&lt; endl &lt;&lt; &quot;FILENAME: &quot;;
          getline(cin, filename);
          IN_FILE.open(filename);
      }
  
      //Read every line from file
      while(!IN_FILE.eof()) {
          getline(IN_FILE, b[k]);
          k++;
      }
      m = k;
      k = 0;
      
      //Compare the arrays and print all elements is array a that are not in array b
      for (int i = 0; i &lt; n; i++)  { 
          int j;
          for (j = 0; j &lt; m; j++) 
              if (a[i] == b[j]) 
                  break; 
    
          if (j == m) 
              cout &lt;&lt; a[i] &lt;&lt; endl; 
      } 
      
      return 0; 
  }
  </code></pre>
  <p>This is the error:</p>
  <pre>checkTester.cpp:25:26: error: no matching function for call to 'std::basic_ifstream&lt;char&gt;::open(std::__cxx11::string&amp;)'
       IN_FILE.open(filename);
  </pre>