maybe i'm complete idiot but i really can't see what's wrong with this:
fin.seekg (0, ios::end);
int length = finc.tellg();
fin.seekg (0, ios::beg);
please excuse pointless function of this programm, it's just a model of what is my problem. The length is always correct, but the final file on the output is never complete copy. At some point it changes the eof and fail bit to true and the rest of the data read are just 0xFF bytes.