Given a bool variable isReadable write some statements that assign true to isReadable if the file “topsecret” exists and can be read by the program and assigns false to isReadable otherwise.

LANGUAGE: C++

CHALLENGE:

Given a bool variable isReadable write some statements that assign true to isReadable if the file “topsecret” exists and can be read by the program and assigns false to isReadable otherwise.

SOLUTION:



ifstream filename;
filename.open("topsecret");

if (filename.fail()){
    isReadable=false;
}else{
    isReadable=true;
}