Hi, i am trying to read from a random access file and display its contents to screen, however when i run the code nothing is displayed. I'm using a struct call "Menu" to store each record in the file and display it as the program moves through the file. Can anyone shed some light on this for me
thank you.
#include <iostream>
#include <fstream
#include <cstdlib>
using namespace std;
struct Menu
{
int idNum;
char foodItem[25];
float price;
char description[60];
};
void OpenInventory();
void main()
{
OpenInventory();
}//end main
void OpenInventory()
{
Menu m;
ifstream infile;
infile.open("Inventory.dat", ios::in | ios::binary);
if(outfile.fail())
{
cout<<"Inventory.dat failed to open!"; exit(1);
}
while(infile >> m.idNum)
{
infile.getline(m.foodItem , 25, ',');
infile >> m.price;
infile.getline(m.description, 60, '.');
infile.seekg(m.idNum * sizeof(Menu));
infile.read(reinterpret_cast<char*>(&m), sizeof(Menu));
cout<<m.idNum << m.foodItem << m.price << m.description <<endl;
}
infile.close();
}//end OpenInventory Function