Posted By

somada141 on 03/12/10


Tagged

file function stream


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

oakdragon
khouser


Check if a file exists (fstreams)


 / Published in: C++
 

  1. bool FileExists(string filename) {
  2.  
  3. ifstream file;
  4. file.open(filename.c_str()); //note that the filename must be a c-string. A string gives an error
  5.  
  6. // Check if the file exists
  7. if (file.is_open() == true) { //the 'is_open()' does all the work
  8. file.close();
  9. return true;
  10. }
  11.  
  12. return false;
  13.  
  14. }
  15.  

Report this snippet  

You need to login to post a comment.