Mega Code Archive

 
Categories / C++ / File
 

Reads the inventory file created by the previous program and displays its contents on the screen

#include <iostream> #include <fstream> using namespace std;     int main() {   ifstream in("INVNTRY"); // input       if(!in) {     cout << "Cannot open INVENTORY file.\n";     return 1;   }       char item[20];   float cost;       in >> item >>  cost;   cout << item << " " << cost << "\n";   in >> item >> cost;   cout << item << " " << cost << "\n";   in >> item >> cost;   cout << item << " " << cost << "\n";       in.close();   return 0; }