I can't edit or replace from text file

Text file (inventory2.text)

100104

Item Date and Time Delivered: Wed Mar 16 10:55:43 2016
Item Name: Pineapple
Item Qty: 3

Item Price: 25
Item Total: 75
_____________________________________

100105

Item Date and Time Delivered: Wed Mar 16 11:00:25 2016
Item Name: Amarga
Item Qty: 3
Item Price: 85
________
Item Total: 255
_____________________________________

100106

Item Date and Time Delivered: Wed Mar 16 11:03:01 2016
Item Name: Tampus
Item Qty: 3
Item Price: 20
_________
Item Total: 60
_____________________________________

100107

Item Date and Time Delivered: Wed Mar 16 11:04:40 2016
Item Name: ahaha
Item Qty: 5
Item Price: 20
_________
Item Total: 100
________________________________________________________

100108

Item Date and Time Delivered: Wed Mar 16 11:05:33 2016
Item ID:
Item Name: sula
Item Qty: 5
Item Price: 10
_________
Item Total: 50
________________________________________________________
100101

Item Date and Time Delivered: Wed Mar 16 11:30:31 2016

Item Name: Apple
Item Qty: 3
Item Price: 86
_________
Item Total: 258
________________________________________________________
100109

Item Date and Time Delivered: Wed Mar 16 12:04:57 2016

Item Name: haha
Item Qty: 5
Item Price: 25
_________
Item Total: 125
________________________________________________________

Item Date and Time Delivered: Wed Mar 16 12:07:59 2016

Item Name: lala
Item Qty: 5
Item Price: 26
_________
Item Total: 130
________________________________________________________
100105

Item Date and Time Delivered: Wed Mar 16 13:24:03 2016

Item Name: aha
Item Qty: 6
Item Price: 58
_________
Item Total: 348
________________________________________________________








My code:
ofstream outFile("replaced.txt");
ifstream readFile("Inventory2.txt");
string readout;
string search, id, name,qty,dat,price,total;
unsigned int skipLines = 0;

cout<< "Enter id which you want Modify\n";
cin >>search;
system("cls");
cout<<"Enter new Item ID\n";
cin>>id;
system("cls");
cout << "Enter new Item Name\n";
cin>>name;
system("cls");
cout<<"Enter new Item Quantity\n";
cin>>qty;
system("cls");
cout<<"Enter new Item Date and Time\n";
cin>>dat;
system("cls");
cout<<"Enter new Item Price\n";
cin>>price;
system("cls");
cout<<"Enter new Item Total\n";
cin>>total;
system("cls");

while(getline(readFile,readout)) {
if (skipLines != 0) {
skipLines--;
continue;
}
else if (readout == search) {
outFile<<search<< endl;
outFile<<id<< endl;
outFile<<name<<endl;
outFile<<qty<<endl;
outFile<<dat<<endl;
outFile<<price<<endl;
outFile<<total<<endl;
skipLines = 6;
}
else {
outFile<<readout;
}
}
}
Last edited on
Just check ur file is opening or not with fail() for example
if (readFile.fail())
{
//print something
}
Topic archived. No new replies allowed.