CJCoding With Joseph
15free / daySign inCreate account

Did the File Open?

Write a function bool canOpen(const string& filename) that tries to open the file for reading and returns true if it opened successfully and false otherwise. The starter already creates the ifstream in; return the result of its is_open() member.

The test prints opened when your function returns true and failed when it returns false. The first test passes a file that exists; the second passes the path missing_dir/notes.txt, which cannot be opened. The two tests print, respectively (see Expected Output).

Do NOT write a main function.

Expected Output:

opened
failed

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Streamsifstream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.