www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/30/04:45:30

From: rjvdboon AT cs DOT vu DOT nl (Boon van der RJ)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: more on file problems
Date: 30 Jul 1998 08:26:10 GMT
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Lines: 47
Message-ID: <6ppan2$1so$1@star.cs.vu.nl>
References: <35BFFB6F DOT A91B7F08 AT clear DOT net DOT nz>
NNTP-Posting-Host: sloep09.cs.vu.nl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jamie Love (jamie DOT love AT clear DOT net DOT nz) wrote:
> Well, because this problem is really annoying, I thought I would create
> a basic program to test my file handling. Coding the file was ok, with
> no warnings on compilation (command line: gxx -Wall -o tst.exe tst.cc)
> but when I run it, I comes up with error writing to file on the first
> integer. The question is, does anyone know why? The file (test.dat) is
> created with length 0 also. Also, if I have mucked up my code then
> please tell me as as far as I can make out, this should work!
> 
> I use:
> bnu281
> djdev201
> gpp281/lgp281
> lgpp280

You are mixing lgpp280 and lgpp281??? This could give any problem you
like;-) with gcc281 use gpp281 and lgp2811.
There was a major change in the c++ library from 280 to 281, IIRC

> int main() {
> 	ofstream infle("test.dat", ios::bin | ios::trunc);
I think you should use: ios::bin | ios:trunc | ios::out
you overwrite the default mode (ios::out) with what you give it, so
include it to retain it.

> 	ifstream outfle;
> 	if(!writeInts(infle)) {
>    	cout << "\nError writing to file";
> 		return 0;
>    }
>    infle.close();
>    outfle.open("test.dat", ios::bin);

I think you should use: ios::bin | ios::in, but you never get to that,
do you?

And by the way, a strange way to name your files:
infle == the output file.
outfle == the file you read from.

> Also, could you please cc this to my email, if possible, thanks
 
I have, and you're welcome,
 Robert.
-- 
rjvdboon AT cs DOT vu DOT nl        | "En dat is niet waar!" sprak (ex?) Staatsecre-
www.cs.vu.nl/~rjvdboon   |    taris Netelenbos (onderwijs) fel.

- Raw text -


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