Thursday 31 May 2018

c++11 - 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?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...