+ 7
files stuck in c++
I have this code that insert an object in a file with maintaining it as a sorted file https://code.sololearn.com/c62ydYrq4QIU/?ref=app but it repeat some elements I don't know why the same code in C (just differs by syntax) works properly 😭
1 Resposta
+ 1
Hi ABADA S
The problem is when copying the file. Using as condition !from.eof is not good. Better use the good() method. Or better just try this:
void fcpy(char*To,char*From) {
ofstream to(To,ios::out|ios::trunc);
ifstream from(From);
user s;
while(from.read((char*)&s,sizeof(s))) {
to.write((char*)&s,sizeof(s));
}
from.close();
to.close();
}