#include #include #include #include using namespace std; const int MAXLENGTH = 21; char filename[MAXLENGTH] = "test.dat"; int main() { ofstream out_file; out_file.open(filename); if (out_file.fail()) { cout << "The file was not successfully opened.\n" ; system( "PAUSE" ); exit( EXIT_FAILURE ); } // This is a different way to 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.; out_file.close(); // Not required because files close automatically // with program termination cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); }