TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CAMERON CLARK
from: DARIN MCBRIDE
date: 1997-08-29 07:58:00
subject: stream bug???

 -=> Quoting Cameron Clark to All
 CC> The following pseudo-code has an unfortunate side effect:
 CC> (using Borland c++ 4.51)
 CC> ofstream outf("out.bin");
ofstream outf("out.bin", ios::out | ios::bin);
 CC> char string[6];
char string[7];
 CC> strcpy(string,"12345");
 CC> string[strlen(string)] = '\n';
This line was writing to string[6].  You probably end up using it all as a
string, and should terminate it...
strcat(string, "\n");
 CC> outf.write(string, strlen(string));
 CC> outf.close();
 CC> The side effect is that it writes the following:
 CC> 12345#13#10           (where #13 & #10 are ascii characters)
PC's convert \n to \r\n in ascii mode.  Changing it to binary mode turns off
this translation.
 CC> What the hell am I doing wrong?
Getting too upset too quickly, I'd bet.  Calm down.  It may be simple for
those of us bitten by this before, but it's an entirely new concept for
everyone else.
... A feature is a bug with seniority.
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

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™.