1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

ifstream problem with reading

Discussion in 'C' started by exot, Oct 24, 2009.

  1. exot

    exot New Member

    Joined:
    Oct 24, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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. :cryin: :cryin:
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Try doing it this way :

    Code:
    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);
    
     

Share This Page