Archive for May, 2020

Standard way to check if a file exist using standard C++ 17

Saturday, May 30th, 2020

Below example to check whether a file exists using standard C++ std::filesystem library

#include <string>
#include <filesystem>

bool is_file_exist( std::string& FileName ) {
	
	const std::filesystem::path p = FileName ;
    return ( std::filesystem::exists(p) );
}

We need g++-8 for this to work, and we must link against -lstdc++fs library.