Mail Archives: djgpp/1999/03/03/18:39:04
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 -