ifstream: how to tell if specified file doesn’t exist

EDIT: I’ve been notified that this does not necessarily indicate a file does not exist, as it may be flagged due to access permissions or other issues as well.

I know I’m extremely late in answering this, but I figured I’d leave a comment anyway for anyone browsing. You can use ifstream’s fail indicator to tell if a file exists.

ifstream myFile("filename.txt");
    if(myFile.fail()){
        //File does not exist code here
    }
//otherwise, file exists

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)