What happens when an existing file is opened using the following statement?
ofstream fout("data.txt");
Options
-
A.
The file is opened only for reading
-
B.
The existing contents are normally truncated
-
C.
The file is always opened in append mode
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
The existing contents are normally truncated
Detailed Explanation
Correct Answer: Option BExplanation:An
ofstream opens a file for output. By default, its output mode normally includes
ios::out and truncates an existing file unless a mode such as
ios::app changes that behavior. Be careful when opening files containing important data.