How To Delete Specific Data From Text File Without Using Vectors

How To Delete Specific Data From Text File Without Using Vectors

1
2
3
4
5
6
7
8
9
10
11
For Example Text File Data
12345
Muhammad Salman
12346
Waleed Karam
12347
Hamza Rizwan

If The User Enter 12345
User 12345
Delete From File


Without Using Vectors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream infile("D:\\input.txt");
    ofstream outfile ("D:\\output.txt");
    cout << "Enter text to delete: \n";
    string reject;
    getline(cin, reject);

    if(infile)
    {
        string line;
        while(getline(infile, line))
        {
            if(line != reject)
            {
                outfile << line << '\n';
            }
        }
    }
}
@gunnerfunenr i try this but this see not to work
ty @chervil you are best
Topic archived. No new replies allowed.