i have a text file with known format. which is as fallow
code ItemName Quantity
001 ABC 45
002 BCA 5
003 ACB 10
i want to read and write the line randomly according to the need of a user.
for example if user want to read the data of Item 002 he just enter the code and read the whole line. not only read he can be able to change the Quantity of Item if any item sail out.
i write the following incomplete code:
#include<iostream.h>
#include<fstream.h>
main()
{
fstream infile;
char head[200000];
char body[40];
long val;
long code;
long SelItem;
infile.open("recor.txt");
if(!infile)
{
cout<<"file canot be open";
exit(1);
}
cout<<"enter item code :"<<'\n';
cin>>code;
cout<<"entre code item detail is as follow ::"<<'\n';
cout<<" code"<<" Name"<<" Quantity";
//get line function to read required data of enter code//
[B]//hair i nead the help//[/B]
cout<<"Enter No Of Itmes Sold :";
cin>>SlItem;
//now subtracting the enter value an Rewright quantity in file//
[B]//hair i nead the help//[/B]
cout<<"Enter Code Item Detail After transaction ::"<<'\n';
cout<<" code"<<" Name"<<" Quantity";
//read the same line and print it after transaction//
[B]//i need help here//[/B]
infile.close();
cout<<'\n';
cout<<'\n';
system("pause");
}