Mail Archives: djgpp/1998/03/26/05:49:55
Hi.
I'm having a bit of trouble using binary streams via djgpp.
The code below (which I borrowed from the Borland support
site) serves to demonstrate the problem; with the MS or
Borland compilers, the two files are created as expected
(text.txt: 49 bytes, bin.txt: 47 bytes), but with DJ the
bin.txt file is empty. Am I missing something?
Any help most appreciated...
Carl Kalauokalani
ckalauokalani AT usa DOT net
==================================================================
//***********************************************************
// Stream.cpp
//
// This is an example of using binary mode streams.
//
//***********************************************************
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <string.h>
int main( void )
{
ofstream ofilet ;
ofstream ofileb ;
float ff = 3.14159 ;
ofilet.open( "text.txt" ) ;
ofileb.open( "bin.txt", ios::binary ) ;
// Write to text-mode file
ofilet << "Float as String: " << ff << "\n" ;
ofilet << "Float as Binary: " ;
ofilet.write( (char *) &ff, sizeof( ff ) ) ;
ofilet << "\n" ;
// Write to binary-mode file
ofileb << "Float as String: " << ff << "\n" ;
ofileb << "Float as Binary: " ;
ofileb.write( (char *) &ff, sizeof( ff ) ) ;
ofileb << "\n" ;
// Write to screen
cout << "Float as String: " << ff << "\n" ;
cout << "Float as Binary: " ;
cout.write( (char *) &ff, sizeof( ff ) ) ;
cout << "( Garbage Expected )\n" ;
return 0 ;
} // ***** end of stream.cpp ********************************
____________________________________________________________________
Get free e-mail and a permanent address at http://www.netaddress.com
- Raw text -