files stuck in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 😭

2nd Dec 2019, 7:10 AM
ABADA S
ABADA S - avatar
1 Answer
+ 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(); }
10th Dec 2019, 12:10 AM
Mark