reads the inventory file created by the previous program and displays its contents on the screen: : Object Serialization « File « C++






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;
}
  
    
  








Related examples in the same category

1.Save object to file with customized operator
2.Using Command-Line Arguments to Get a Filename