Mail Archives: djgpp/2001/12/17/18:03:06
Hi,
I was testing code that I was able to run using VC++6 without a hitch, but djgpp is giving me the compile time error:
no matching function for call to
`std::basic_ofstream<char, std::char_traits<char> >::write(unsigned char*&, unsigned int)'
c:/djgpp/lang/cxx-v3/bits/ostream.tcc:
because I try to read data from and write to files using
ofstream's .write((unsigned char*) &ut, sizeof(unsigned char))
and
unsigned char* ucAr = new unsigned char[ASCIIVOL];
ifBinStrm.read((unsigned char*) ucAr, ASCIIVOL);
Is there a way to make the compiler/linker swallow these kinds of C-like code and keep going?
My question would be then. How do you read/write a number of raw bytes from/to a file?
Thanks
// - - - - - - CODE EXAMPLE - - - - - - - -
#include <fstream.h>
// __ Constant
const unsigned int ASCIIVOL = 256;
int main(void){
unsigned int ut, utStrt = 0, utTp = ASCIIVOL;
// __ writing byte size binary data
ofstream ofBinStrm;
ofBinStrm.open("TmpFl.bin.", ios::out|ios::binary);
for(ut = 0; (ut < utTp); ++ut){ ofBinStrm.write((unsigned char*) &ut, sizeof(unsigned char)); }
cerr << " ofBinStrm.tellp()=" << ofBinStrm.tellp() << endl;
ofBinStrm.close();
// __ Opening file as ifstream
ifstream ifBinStrm;
ifBinStrm.open("TmpFl.bin.", ios::in|ios::binary);
// __ Dumping file at once on the array
unsigned char* ucAr = new unsigned char[ASCIIVOL];
ifBinStrm.read((unsigned char*) ucAr, ASCIIVOL);
cerr << " ifBinStrm.tellg()=" << ifBinStrm.tellg() << endl;
ifBinStrm.close();
// __ printing array
for(ut = 0; (ut < utTp); ++ut){
cerr << ut << "," << (unsigned int)ucAr[ut] <<", ucAr[" << ut << "]=" << ucAr[ut] << endl;
}
delete[] ucAr;
// __
return(0);
}// main
- Raw text -