title: Passing absolute file name to read file in c++
body: <p>// I am trying to read a file inside a function by calling the function in main and passing the file name as an argument. It's giving an error in opening the file.But same works fine when I pass the file name directly file("file_name"). Why is it so? Thanks in advance.</p>
  
  <pre><code>#include&lt;string&gt;
  #include&lt;fstream&gt;
  void parse(string file_name)
  {
     ifstream file("file_name"); //opens file
     if (!file)
     {  
        cout&lt;&lt;"Cannot open file\n";
        return; 
     }  
     cout&lt;&lt;"File is opened\n";
     file.close(); //closes file
  }
  
  int main()
  {
     parse("abc.txt"); //calls the parse function
     return;   
  }  
  </code></pre>