dimanche 24 novembre 2019

How to check if a file exists in C++?

I want to determine if a file exists in C++ 11

I have the following codes:

ifstream inputFile(c);

if (!inputFile.good()) {
        std::cout << "No file found" << '\n';           
}

And

if (inputFile.peek() == std::ifstream::traits_type::eof()){
           ....
}

Which one is correct and idiomatic?

Aucun commentaire:

Enregistrer un commentaire