How do i go about updating a specific record in sequential File using a primary key in c++.
I used Inventory number as my primary key..please any assistance?
Code:
int locate[2];
string fname, lname, add, name, address;
int num, foundit;
Customer customer;
long len;
ifstream file("Clinic Files.txt", ios::in);
//len = sizeof(Customer);
cout << "Enter Inventory number for customer you would like to Update" << endl;
cin >> locate[0];
file.seekg(0, ios::beg); //0 bytes from beginning of file(ios::beg)
//CHECKS IF USER EXITS IN SYSTEM
while(file >> locate[1] >> fname >> lname >> num >> address){
if (locate[0] == locate[1]){
foundit = 1;
cout << "Success User was found " << endl;
cout << "Select the data field you want to change" << endl;
int findIt = 0;
cout << "1-Firstname" << endl;
cout << "2-LastName" << endl;
cout << "3-Phone Number" << endl;
cout << "4-Address" << endl;
cin >> findIt;
string No, Fname, Lname, Add, Phone;
// int Phone;
fstream file("Clinic Files.txt", ios::in | ios::out);
file >> No >> Fname >> Lname >> Phone >> Add;
if (findIt == 1){
int n;
string a;
cout << "Enter The Updated Firstname" << endl;
cin >> a;
n = a.size();
cout << n;
file.seekg(0, ios::beg); //move the put cursor to start of "text"
for (int i = 0; i<n; i++){
file << a;
}
file.close();
break;
}