Oct 9, 2009 at 8:40am UTC
void main()
{ clrscr();
fstream frnd;
frnd.open("C:/store.txt", ios::in|ios::out);
if(!frnd)
{ cout<<"\nMemory Error!!!!";
getch();
exit(1);
}
int quant,count=0;
float rate;
char name[25], ch, ans='y';
/* File write */
while(ans=='y'||ans=='Y')
{ cout<<"\n\nEnter Item Name : "; cin.getline(name,25);
cout<<"\nEnter Rate : "; cin>>rate;
cout<<"\nEnter Quantity : "; cin>>quant;
cout<<"\nWanna enter more items?(y/n) : ";
cin>>ans;
frnd<<name<<endl<<rate<<endl<<quant<<endl;
cin.get(ch);
count++;
}
clrscr();
cout<<"file wil nw b read\n\n";
getch();
/* File read */
frnd.seekg(0);
while( count-- >0 )
{ frnd.getline(name,25,'\n');
frnd>>rate;
frnd.get(ch);
frnd>>quant;
frnd.get(ch);
cout<<"\n\nItem Details : "
<<"\n\tName : "<<name
<<"\n\tRate : "<<rate
<<"\n\tQuantity : "<<quant;
}
getch();
frnd.close();
}
In the while loop of the file write portion of the program, what does the statement : cin.get(ch); do?
If I dont use this statement, then while I try to display the output, output is incorrect.
Please help!!!!