0

How to delete a selected data from a file

Hey guys I am working on a project. In my project i have a option called modify data. When you use that You need enter the student's roll no to modify that students data. example the student current data is Name : McAwesome Roll : 102 now you choose that option modify data and enter 102 and put the name McRAS and roll 103 how I do that ?? how I make that code to find that data inside my file which contains the roll no 102 and let the use to modify that data?? please help me

8th Dec 2017, 3:43 PM
Rafi Ahmed Saad
Rafi Ahmed Saad - avatar
2 Respuestas
+ 2
The simplest thing you can do is read all data entries from the file one by one, and write them to a temporary file only if they don't match the data to be modified. When the data is a match, you modify that object data and then write it in the temporary file. In the end, you delete the original file and rename the temporary file to the original name. If you don't want to use multiple files, you may use seekg, to reach each object's roll number one by one, just read the roll number, and if its match, go back to the start of that object and overwrite data at the same position again. This method, however requires you to know the exact size of the object so that you can know where to read/write from/to.
8th Dec 2017, 4:16 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
ok thank you I am working on it
9th Dec 2017, 6:02 PM
Rafi Ahmed Saad
Rafi Ahmed Saad - avatar