i have a program in which i want to replace student data by user in text file .
i also want to delete data by user choice . any one can help me in this program?
#include<iostream>
#include<fstream>
using namespace std;
int regno;
void update();
void deletee();
fstream var;
int main()
{
var.open("abdullah.txt");
update();
var.close();
}
void update()
{
cout<<"\nEnter registration number of student whose record you want to update\n";
cin>>regno;
//incomplete
}
void deletee()
{
cout<<"\nEnter registration number of student whose record you want to delete\n";
cin>>regno;
//incomplete
}
file
Records of student
1nd student :
a) Registration number 1
b) Name f
c) Semester g
d) Subject d
Records of student
2nd student :
a) Registration number 2
b) Name qqq
c) Semester www
d) Subject eee
In what format is your file in? It is most important when it comes to file handling. If your file format is consistent this is very easy to do with std::vector and std::string. Load the file into data records, search through each record for regno, then you can erase that record.
Make sure to load the file into memory as it is much quicker to alter than data on disk. Secondly you can write out the very same vector to save your changes to the original file.
For more help please show the format of "abdullah.txt".