in-and-out Needs an Existing File
easyQuestion 649Write a function bool openReadWrite(const string& filename) that opens filename with an fstream in ios::in | ios::out mode and returns whether the open succeeded (the result of is_open()). Do not write anything to the file, and print nothing to cout; the test prints the result itself.
The test prints opened when your function returns true and failed when it returns false. The first test creates data_a.txt before calling you, so it prints the output shown in Expected Output.
The second test passes the path missing_dir/data.txt, so it prints:
failed
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
Streamsfstream
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.