www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000256

When Created: 11/08/1998 01:00:13
Against DJGPP version: 2.01
By whom: wayers@erols.com
Abstract: ifstream char* buffer automatic variable only good for one call. DJGCC 2.81
This function will always work on the first call and will never work on immediate 
succesive tries.

void read(){

   char* instr;
   fstream fs;
   fs.open(filename,ios::in);
        
   while(!fs.eof()){

        fs.get(instr,10);
        cout << "Data " << instr << endl;
   }
   fs.flush();
   fs.close();   
}

Workaround added: 11/08/1998 01:00:01
By whom: wayers@erols.com
If the char* is a parameter it works fine every time.

void read(char* instr){


   fstream fs;
   fs.open(filename,ios::in);
        
   while(!fs.eof()){

        fs.get(instr,10);
        cout << "Data " << instr << endl;
   }
   fs.flush();
   fs.close();   
}

Closed on 11/11/1998 10:00:49: Poor technique, I just needed to allocate memory
By whom: wayers@erols.com



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010