C++ ofstream setiosflags(ios::showpoint)
#include <iostream> #include <fstream> #include <cstdlib> #include <string> #include <iomanip> using namespace std; int main()// w ww . j ava 2s . c o m { string filename = "prices.dat"; ofstream outFile; outFile.open(filename.c_str()); if (outFile.fail()) { cout << "The file was not successfully opened" << endl; exit(1); } // Set the output file stream formats outFile << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2); // Send data to the file outFile << "Hats " << 3.95 << endl << "Bulbs " << 0.22 << endl << "Cases " << 11.08 << endl; outFile.close(); cout << "The file " << filename << " has been successfully written." << endl; return 0; }