143k views
1 vote
Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would write the value of the salary variable to the file

A) cout < B) ofstream C) dataFile << salary;
D) payroll.dat <

User Cyberpks
by
3.8k points

1 Answer

4 votes

Answer:

dataFile << salary;

Step-by-step explanation:

To write salary to a file (payroll.dat) using ofstream, you make use of the following instruction:

ofstream dataFile;

myfile.open ("payroll.dat");

myfile <<salary;

myfile.close();

This line creates an instance of ofstream

ofstream dataFile;

This line opens the file payroll.dat

myfile.open ("payroll.dat");

This is where the exact instruction in the question is done. This writes the value of salary to payroll.dat

myfile <<salary;

This closes the opened file

myfile.close();

User Captainsac
by
3.0k points