#include #include #include int main() { const int MAXLENGTH = 21; // maximum file name length const int MAXCHARS = 31; // maximum description length char filename[MAXLENGTH] = "prices.dat"; char descrip[MAXCHARS]; int ch; float price; ifstream inFile; inFile.open(filename, ios::nocreate); if (inFile.fail()) // check for successful open { cout << "\nThe file was not successfully opened" << "\n Please check that the file currently exists." << endl; exit(1); } // set the format for the standard output stream cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2); cout << endl; // start on a new line // read and display the file's contents while ( (ch = inFile.peek()) != EOF ) // check next character { inFile >> descrip >> price; // input the data cout << descrip << ' ' << price << endl; } inFile.close(); cout << endl; return 0; }