I'm writing a program for data handling using files in c++.
I have provisions for inserting, deleting, modifying and displaying records.
This is menu driven, hence after you do one of these, it prompts you for another action.
ie
while(ch)
cin>>ch;
switch(ch)
{case 1: //insert
case 2://modify
//and so on
}
The problem is, once I modify an element, it prompts for another action, as required. This time, it takes the input but doesn't give the output. It shows output correctly in the next prompt.
What could be the reason for this?
Am enclosing relevant parts of code :
'file' is an fstream object tied to the concerned file.
//modification
cout<<"\nEnter itemcode of item to be modified ";
cin>>icode;
file.seekg(0,ios::beg);
while(file)
{ file.read((char*)&i,sizeof(i));
if(icode==i.givedata()&&file)
{ pos=file.tellg();
cout<<"\npos="<<pos<<endl;
cout<<"\nEnter new values\n";
i.getdata();
file.seekg(pos-sizeof(i));
file.write((char*)&i, sizeof(i));
}
}
file.seekg(ios::end);
//display
file.seekg(0,ios::beg);
cout<<"\nContents of file\n";
file.seekp(0,ios::beg);
while(file.read((char*)&i,sizeof(i)))
i.putdata();
file.clear();
break;
Please help soon.
Rates assured.
Thanks:-)