1. I need to know why i got this error.
2. I have 20 choclate stock information. I don't know how to read and update the information.
It would be grat pleasure if you can help me for this programme.
Here is the code:
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct Supplier
{
char sname[50];
char saddress[50];
char sphone[50];
};
struct Chocolate
{
char cname[100];
char ctype[100];
char qty[100];
char ppp[100];
Supplier supply;
}choco[20];
int main()
{
int num;
ifstream infile;
infile.open("choc.txt");
if(!infile.eof())
{
infile>>num;
for(int i=0; i<num; i++)
{
infile.getline(choco[i].cname,50,'\n');
infile.ignore();
infile.getline(choco[i].ctype,50,'\n');
infile.ignore();
infile.getline(choco[i].qty,50,'\n');
infile.ignore();
infile.getline(choco[i].ppp,50,'\n');
infile.ignore();
infile.getline(choco[i].supply.sname,50,'\n');
infile.ignore();
infile.getline(choco[i].supply.saddress,50,'\n');
infile.ignore();
cout<<choco[i].cname<<endl;
cout<<choco[i].ctype<<endl;
cout<<choco[i].qty<<endl;
cout<<choco[i].ppp<<endl;
cout<<choco[i].supply.sname<<endl;
cout<<choco[i].supply.saddress<<endl;
cout<<choco[i].supply.sphone<<endl;
}
}
return 0;
}
This post has been edited by JackOfAllTrades: 19 November 2012 - 08:35 AM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote





|