1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
void Product::Delete()
{
Product del, infos;
bool found = false;
fstream file("h2td.txt", ios::in);
//***********************************************************************
cout << "Enter Code to Search: ";
getline(cin,scode);
do
{
getline(file, z, '~');
getline(file, code, '~');
getline(file, gName, '~');
getline(file, price, '~');
if (scode!=code)
{
found = false;
// while(!file.eof() && found == false) //if i remove this, then the program continues on. with it, its just stuck there..
// {
fstream file2("temp.txt", ios::out | ios::app);
file2 << z << '~';
file2 << code << '~';
file2 << gName << '~';
file2 << price << '~' << endl;
file2.close();
// };
}
else
{
found = true;
}
}while(!file.eof() && found == false);
//************************************************************************
if (found == true)
{
cout << "Record Found!" << endl;
cout << z << "\nCode: " << code;
cout << "\nGeneric Name: " << gName;
cout << "\nUnit Price: " << price;
//*******************************************************************
cout << "\n" << "-----------------------------------------------------------------" << endl;
isthis(); // returns bool true if this is the record that the user wants deleted
if(thiz == true)
{
cout << "Record Deleted!" << endl;
file.close();
remove("h2td.txt");
rename("temp.txt","h2td.txt");
}
}
else
{ cout << "Record not found" << endl; }
file.close();
system("PAUSE");
Menu();
}
|