open file with full path and delete a line in big file

Here i m removing the line from a big file i wrote the code which is working fine as below but..
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
26
27
28
29
30
31
32
33
34
35
36
37
38

#include <stdio.h>
#include <fstream>
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
    string line;
    char buf[1024]="";
    char rembuf[1024]="";
    snprintf(buf,sizeof(buf) -1,"%s/file.txt",path.c_str());
    snprintf(rembuf, sizeof(rembuf) -1, "%s/tempfile.txt", path.c_str());

    ifstream in(buf);
//    printf("%s\n",buf);
   
    if(!in.is_open())
    {
          cout << "failed to open\n";
          return 0;
    }
    ofstream out("tmpfile.txt");

    while( getline(in,line) )
    {
        if(line != "stringdelete")
            out << line << "\n";
    }
    in.close();
    out.close();

   unlink(rbuf);
   rename(rembuf,rbuf);

    return 0;
}


is this correct procedure for big files? anyone can help me in this thanks in advance.


Last edited on
Topic archived. No new replies allowed.