Q: 1 Which of the following statements is/are correct?
1. It is not possible to combine two or more files opening mode in open() method.
2. It is possible to combine two or more files opening mode in open() method.
3. ios::in and ios::out are input and output file opening modes respectively.
1, 3
2, 3
3 only
1 only
[ Option B ]
In C++, when working with files, the open() method of file streams allows you to specify the mode in which the file should be opened.
Q: 2 What is the use of ios::trunc mode?
To open a file in input mode
To open a file in output mode
To truncate an existing file to zero
More than one of the above
[ Option C ]
In C++, file streams use modes to control how files are opened and accessed. The ios::trunc is a file mode used with output streams. Its purpose is to truncate an existing file, which means it deletes all the current content of the file and makes its size zero before writing new data.
#include <fstream>
using namespace std;
int main() {
ofstream file("myfile.txt", ios::out | ios::trunc);
file<<"New Content Added.";
file.close();
return 0;
}
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.