From: deepblack AT geocities DOT com (Luis Coelho) Newsgroups: comp.os.msdos.djgpp Subject: Re: ios::binary ignored by GCC - HELP! Date: Sat, 07 Nov 1998 23:24:26 GMT Organization: Instituto Superior Tecnico Lines: 33 Message-ID: <3644d428.2862999@news.ist.utl.pt> References: NNTP-Posting-Host: ppp14.ist.utl.pt X-Trace: ci.ist.utl.pt 910477132 11393 (None) 193.136.102.46 X-Complaints-To: news AT news DOT ist DOT utl DOT pt X-Newsreader: Forte Free Agent 1.1/32.230 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Fri, 06 Nov 1998 20:36:14 -0500 (EST), "sl" uttered the following words: > When I open files in ios::binary mode, it is ignored by GCC. For >example, writting "7" to a file opened with the binary flag should write the >7th ASCII character. Instead, the file contains the text-character "7".. How >does one go about fixing this? > >Gili Are you using something such as ofstream fout("filename.dat", ios::binary); int the_int = 7; fout << the_int << 42; ? operator<< *Always* outputs a character representation of its second argument. To output integrers in binary, you must use write(). So the example above becomes: fout.write(static_cast(&the_int),sizeof(int)); Hope that helped, Luís Coelho. ******* Translations: Any combination between German, English & Portuguese. Contact me at deepblack AT geocities DOT com ******* C++ Programming Language, 3rd Ed. by B. Stroustrup. My exercise answers at: http://www.geocities.com/SiliconValley/Way/3972/index.html