delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/03/18:39:04

Message-ID: <36DDC82A.B973BDBA@unb.ca>
Date: Wed, 03 Mar 1999 19:39:23 -0400
From: Endlisnis <s257m AT unb DOT ca>
X-Mailer: Mozilla 4.04 [en] (Win95; U)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
To: djgpp AT delorie DOT com
Subject: Re: (Problem with structs)
References: <36DDBF84 DOT 438669BC AT solutions2000 DOT net>
X-Info: BrunNet, Inc. 888-278-6638
Reply-To: djgpp AT delorie DOT com

Nehru Juman wrote:

> I'm having a problem with a program I took directly from a c++ book ("A
> Beginners C++) which involves writing structs to disk.  Since it comes
> from the book I assume it should work.  I wrote a simplified program to
> isolate the problem.  Can anybody tell me why the below code doesn't
> work properly:

[snip]

> alpha beta[20]={{10,"abcd"},{20,"efgh"},{30,"ijkl"},                   ^^
note the 10.[snip]

>      gDataFile.open("testfile.my",ios::in|ios::out);

    The problem is with the DOS implimentation of "newline"s.  In DOS, a
'newline' is represented as CR, LF (13,10).  And for fstream to write text
files that standard text editors can read, any time you try to write byte
value 10, a byte value 13 is written as well.  You can override this in the
open line:
     gDataFile.open("testfile.my",ios::in|ios::out|ios::binary);
    That fixes the problem (I tried it, and it works).
--
     (\/) Endlisnis (\/)
          s257m AT unb DOT ca
          Endlisnis AT GeoCities DOT com
          Endlisnis AT BrunNet DOT Net
          Endlisnis AT HotMail DOT com


- Raw text -


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