ifstream problem with reading

exot's Avatar, Join Date: Oct 2009
Newbie Member
hi guys,

maybe i'm complete idiot but i really can't see what's wrong with this:

Code:
ifstream fin("data.pdf");
  ofstream fout("bleah.pdf");
  
  fin.seekg (0, ios::end);
  int length = finc.tellg();
  fin.seekg (0, ios::beg);
  
  for(int i=0;i<length;i++){
      fout.put(fin.get());
    }
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.
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
Try doing it this way :

Code: C++
ifstream fin("data.pdf");
ofstream fout("bleah.pdf");
char ch;

fin.seekg (0, ios::end);
unsigned int length = fin.tellg();
fin.seekg (0, ios::beg);
 
while((ch=fin.get())!=EOF)    fout.put(ch);