www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/25/20:29:40

Message-ID: <3633DDE8.9016BCDE@montana.com>
Date: Sun, 25 Oct 1998 19:26:48 -0700
From: bowman <bowman AT montana DOT com>
X-Mailer: Mozilla 4.5b2 [en] (Win95; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: fstream ios::binary problem
References: <36339807 DOT 18DBCCF6 AT arctic DOT net>
Reply-To: djgpp AT delorie DOT com


"Benjamin R. Saylor" wrote:
> 
> I wrote this code to write a series of numbers (short wave[11025]) to a
> binary file.  the program produces a 57k file (rather than 22k) and I
> looked at it in ms-dos editor to discover that the program output the
> numbers as text, like cout would.  Why doesn't ios::binary work?

ios::binary isn't your problem, it is the 'put to' operator <<. Think of
it
as sort of a hardwired fprintf. the << for any built-in type has one
mission in
life: turning that data into a formatted textual representation. see
Stroustrup's 3rd,
21.2.2

 try the 'write' ostream class member. don't
let the 'char' in the prototype throw you, you just need to pass
&someval and sizeof(someval)  to write ints, doubles, structures, or
what have you.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019