#include <fstream.h>
#include <stdlib.h>
#include <iomanip.h>
const int MAXLENGTH = 21; // maximum file name length
char filename[MAXLENGTH] = "prices.dat"; // put the filename up front
int main()
{
ofstream out_file;
out_file.open(filename);
if (out_file.fail())
{
cout << "The file was not successfully opened" << endl;
exit(1);
}
// set the output file stream formats
out_file << setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(2);
// send data to the file
out_file << "Batteries " << 39.95 << endl
<< "Bulbs " << 3.22 << endl
<< "Fuses " << 1.00;
out_file.close();
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.twbbs.org)
◆ From: ntumcc66.mba.ntu.edu.tw