What does the following C++ code do?
ofstream fout("log.txt", ios::out | ios::app);
fout << "New entry";
fout.close();
Options
-
A.
Reads the file contents
-
B.
Appends New entry to the file
-
C.
Always deletes the file contents before writing
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
Appends New entry to the file
Detailed Explanation
Correct Answer: Option BExplanation:ios::app makes every write occur at the end of the file. Therefore, the text
New entry is appended instead of replacing existing contents. If the file does not exist, the output stream can create it.