Related questions with answers
Question
Write a program segment that defines a file stream object named employees. The file should be opened for both input and output (in binary mode). If the file fails to open, the program segment should display an error message.
Solutions
VerifiedSolution A
Solution B
Solution C
Answered 1 year ago
Answered 4 months ago
Step 1
1 of 2//declare object and open file directly
fstream employees("employees.dat", ios::in | ios::out | ios::binary);
//display error if file was not opened
if(!employees)
cout << "Error opening the file!";
Answered 4 months ago
Step 1
1 of 2To create a file stream object, we need to include fstream
header.
Once that is done, an object of type fstream
can be created. In
order to specify that created object should be used for input and output
and that it is working with binary files, we pass file mode flags in
constructor of fstream
object. File mode flags can be combined using
operator
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
Create an account to view solutions
By signing up, you accept Quizlet's Terms of Service and Privacy Policy
More related questions
1/4
1/7