X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <3C1F06BF.1C600376@earthlink.net> From: Martin Ambuhl Organization: Nocturnal Aviation X-Mailer: Mozilla 4.77 [en] (Win95; U) X-Accept-Language: en,de-CH,fr,ru,zh-CN,ja MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: no matching function for call References: <1008615695 DOT 246552 AT news> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 89 Date: Tue, 18 Dec 2001 09:04:59 GMT NNTP-Posting-Host: 165.247.31.18 X-Complaints-To: abuse AT earthlink DOT net X-Trace: newsread1.prod.itd.earthlink.net 1008666299 165.247.31.18 (Tue, 18 Dec 2001 01:04:59 PST) NNTP-Posting-Date: Tue, 18 Dec 2001 01:04:59 PST X-Received-Date: Tue, 18 Dec 2001 01:05:00 PST (newsmaster1.prod.itd.earthlink.net) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com CPPNewbie wrote: > > 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 >::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? Below are the changes I made to your code to make it compilable without diagnostics, followed by the resulting code. [Changes] 1c1,3 < #include --- > #include > #include > using namespace std; 8c10 < unsigned int ut, utStrt = 0, utTp = ASCIIVOL; --- > unsigned int ut, utTp = ASCIIVOL; 14c16 < ofBinStrm.write((unsigned char *) &ut, sizeof(unsigned char)); --- > ofBinStrm.write((char *) &ut, 1); 25c27 < ifBinStrm.read((unsigned char *) ucAr, ASCIIVOL); --- > ifBinStrm.read((char *) ucAr, ASCIIVOL); [Resulting code] #include #include using namespace std; // __ Constant const unsigned int ASCIIVOL = 256; int main(void) { unsigned int ut, 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((char *) &ut, 1); } 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((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