i cannot get the output by using the function showdata()..... ...plz run this code and send the solution on my ID <ID removed by weaknessforcats >
// A PROGRAME TO OPERATE SOME FILE RELATED OPERATIONS....
#include<iostre am.h>
#include<fstrea m.h>
#include<conio. h>
class stock
{
public:
int no;
char mfd[10]; // DD/MM/YYYY
char exp[10]; // DD/MM/YYYY total 10 digits
};
void get()
{
clrscr();
stock stk;
cout<<"\n enter serial no : " ;
cin>>stk.no;
cout<<"\n enter mfd in DD:MM:YYYY formate : ";
cin>>stk.mfd;
cout<<"\n enter date of exp : ";
cin>>stk.exp;
ofstream fout;
fout.open("d:/stock.txt",ios: :binary);
fout.seekp(ios: :end);
fout.write((cha r*) &stk ,sizeof stk);
fout.close();
}
void showdata()
{
ifstream fin;
stock stk;
fin.open("d:/stock.txt",ios: :binary);
fin.seekg(ios:: beg);
fin.read((char *) &stk,sizeof stk);
cout<<"serial : "<<stk.no;
cout<<"\n mfd : "<<stk.mfd;
cout<<"\n exp : "<<stk.exp;
}
void main()
{
stock stk;
void get(void);
void showdata(void);
int choice;
cout<<"\n enter your choice :\n enter 1 for input and 2 for show data : ";
cin>>choice;
switch(choice)
{
case 1:
get();
break;
case 2:
showdata();
break;
}
getch();
}
// A PROGRAME TO OPERATE SOME FILE RELATED OPERATIONS....
#include<iostre am.h>
#include<fstrea m.h>
#include<conio. h>
class stock
{
public:
int no;
char mfd[10]; // DD/MM/YYYY
char exp[10]; // DD/MM/YYYY total 10 digits
};
void get()
{
clrscr();
stock stk;
cout<<"\n enter serial no : " ;
cin>>stk.no;
cout<<"\n enter mfd in DD:MM:YYYY formate : ";
cin>>stk.mfd;
cout<<"\n enter date of exp : ";
cin>>stk.exp;
ofstream fout;
fout.open("d:/stock.txt",ios: :binary);
fout.seekp(ios: :end);
fout.write((cha r*) &stk ,sizeof stk);
fout.close();
}
void showdata()
{
ifstream fin;
stock stk;
fin.open("d:/stock.txt",ios: :binary);
fin.seekg(ios:: beg);
fin.read((char *) &stk,sizeof stk);
cout<<"serial : "<<stk.no;
cout<<"\n mfd : "<<stk.mfd;
cout<<"\n exp : "<<stk.exp;
}
void main()
{
stock stk;
void get(void);
void showdata(void);
int choice;
cout<<"\n enter your choice :\n enter 1 for input and 2 for show data : ";
cin>>choice;
switch(choice)
{
case 1:
get();
break;
case 2:
showdata();
break;
}
getch();
}
Comment