← Back to Streams
Question 649
in-and-out Needs an Existing File
in-and-out Needs an Existing File
Write a functionbool openReadWrite(const string& filename)that opensfilenamewith anfstreaminios::in | ios::outmode and returns whether the open succeeded (the result ofis_open()). Do not write anything to the file, and print nothing tocout; the test prints the result itself. The test printsopenedwhen your function returns true andfailedwhen it returns false. The first test createsdata_a.txtbefore calling you, so it prints the output shown in Expected Output. The second test passes the pathmissing_dir/data.txt, so it prints: failed 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
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.