Given a bool variable fileExists write the necessary code to set this variable to true if the file “crucial_data” exists and sets it to false otherwise.

LANGUAGE: C++

CHALLENGE:

Given a bool variable fileExists write the necessary code to set this variable to true if the file “crucial_data” exists and sets it to false otherwise.

SOLUTION:



fstream dataFile;
dataFile.open(""crucial_data"",ios::in);
if (!dataFile.fail()){
    fileExists=1;
}else{
    fileExists=0;
}