Did the File Open?
easyQuestion 576Write 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, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
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.