CJCoding With Joseph
15free / daySign inCreate account

in-and-out Needs an Existing File

Write 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 — print one after the last line.

Hints2 available
Topics:
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.