I wrote this code and now I wanna do sth more. How can I do this: Program asks user to input his ID and When user entered his ID, If his ID is in the file (if (inputID==stud.id) ...) He could delete or update his information.
I really don't know how to do this. So I'm waiting for your help. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
#include<fstream>
usingnamespace std;
struct student{
int id;
char family[10], name[10];
};
void main()
{
student stud;
ofstream sfile("student.dat", ios::out);
cout<<"enter your ID, Name and Family: ";
cin>>stud.id>>stud.name>>stud.family;
cout<<"============="<<endl;
sfile<<stud.id<<stud.name<<stud.family;
}
One way to do is to read the content of the file line by line and write it to other file except the line which have same id which the user has entered and then rename the file .
I read the article but it wasn't what I'm searching for.
I wanna give the ability of updating STUDENT INFORMATION such as deleting, updating, searching and etc to users.
You have to read the file into the program and create a database. Then update the info within the program and rewrite the file completely. I don't believe that you can selectively delete info from a file. Therefore you have to learn how to serialize the elements of your database so that you can read the file, build the database, modify the database, and then rewrite the file.