Hello, I was trying to implement data structures using file operations. I am using a data structure of two integers, one being the index number and other being the value. My actual aim is to recreate the file containing the data using a log. But, the program isn't running as required. Please help.
I am giving the code:
ifstream rlist;
rlist.open("redo.txt",ios::in);
ofstream datt;
datt.open("datatemp.txt",ios::out);
dat c;
char s;
while(!rlist.eof()){
rlist>>s;
if(s=='I'){
rlist.read((char*) &c,sizeof c);
datt.write((char*) &c,sizeof c);
}
if(s=='D'){
ifstream rlistd;
rlistd.open("datatemp.txt",ios::in);
rlist.read((char*) &c,sizeof c);
ofstream rlistdw;
dat s;
rlistdw.open("datatem.txt",ios::out);
while(!rlistd.eof()){
rlistd.read((char *) &s, sizeof s);
if((s.a)!=(c.a))
rlistdw.write((char*) &s, sizeof s);
}
rlistd.close();
rlistdw.close();
remove("datatemp.txt");
rename("datatem.txt","datatemp.txt");
}
Here, "redo.txt" is my log file. And dat is the structure name. The insert(s=='I') thing is working correct but there is some problem with delete one.
And is that true that we can't access the same file using two file pointers at the same time.
Waiting for reply...