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

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.

Tags: ,

Comments are closed.