Correct option is A
Statement 1: "It is not possible to combine two or more file opening modes in open() method." Correct
· In C++, the open() method does not allow multiple file opening modes to be combined directly.
· The open() method can only be used to open one file at a time.
· However, multiple flags (modes) can be combined using bitwise OR (|), but not multiple files in one call.
Statement 2: "It is possible to combine two or more file opening modes in open() method." Incorrect
· This statement is incorrect because the open() method cannot open multiple files at once.
· It can, however, combine multiple modes (ios::in | ios::out).
Statement 3: "ios::in and ios::out are input and output file opening modes, respectively." Correct
· ios::in → Opens a file in input (read) mode.
· ios::out → Opens a file in output (write) mode.
· These modes are used with ifstream, ofstream, and fstream.
Example of File Opening Modes in C++:
#include <fstream>
using namespace std;
int main() {
fstream file;
file.open("example.txt", ios::in | ios::out | ios::app); // Combining file modes
return 0;
}
· Here, ios::in | ios::out | ios::app combines multiple modes, but only for one file at a time.
Knowledge Booster:
· ios::binary is used for opening files in binary mode.
· ios::trunc is used to delete file content when opening in output mode.
· Use fstream when you need both read and write operations.
