2.
Assume that each of the following statements applies to the same program.
a.
Write a statement that opens file
oldmast.dat
for
input; use an ifstream object called
inOldMaster.
b.
Write a statement that opens file
trans.dat
for reading
and writing data to it; use fstream object
transFile
that can read data from the file trans.dat
as well as write data to it.
c.
Write a statement that writes a record to the transfile. The record to store consist of an integer data
accountNumber
, and a floating point data
dollarAmount
#include <fstream>
using namespace std;
int main()
{
// a
ifstream inOldMaster;
inOldMaster.open("oldmast.dat");
// b
fstream transFile;
transFile.open("trans.dat");
// c
int accountNumber = 272445;
double dollarAmount = 2647.27;
transFile << accountNumber << " " << dollarAmount << endl;
inOldMaster.close();
transFile.close();
return 0;
}
Comments
Leave a comment