TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CAMERON CLARK
from: HERBERT BUSHONG
date: 1997-08-26 08:33:00
subject: stream bug???

::>     The following pseudo-code has an unfortunate side effect:
::>     (using Borland c++ 4.51)
Not a side effect, it's working correctly.
::>     ofstream outf("out.bin");
Default's to text mode unless you use the ios::binary open mode.
::>     char string[6];
::>     strcpy(string,"12345");
::>     string[strlen(string)] = '\n';
::>     outf.write(string, strlen(string));
on ostreams (and this is OS dependent I believe), when writing out the char 
'\n' in text mode, it get's converted to a Carriage Return/Linefeed Pair.
which is 0x0D 0x0A  (ascii 13 10).
::>     outf.close();
::>     The side effect is that it writes the following:
::>     12345#13#10           (where #13 & #10 are ascii characters)
::>     What the hell am I doing wrong?
Nothing. If you don't want the conversion, change the open line to:
ofstream outf("out.bin", ios::out | ios::binary);
#  Herbert Bushong    harchon@centuryinter.net       [TEAM OS/2]    
-  Blackbeard's BBS   Intelec: 239:600/0            
+  Fido: 1:19/19      http://www.intelec.com/software/
---
   RM 1.31 2508   Raw Data: A naked android.
---------------
* Origin: Blackbeard's BBS - Ville Platte, LA - 318-468-3385 (1:19/19)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.