How to find and replace text in file by user

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
Hi,
Firstly, have you ever tried to read a file?
Hello Abdullah,

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".
yes i can read the file
megatron txt is the format of file
and i never use vectors . can u teel me the method using string plz
Last edited on
thanks for help guys . i have got it :)
Topic archived. No new replies allowed.