This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Problem with fstream.


Hi,

Following your different answers, I think that I've found a solution.

Rup wrote:

> To access D: from Interix 3.0+ you use /dev/fs/D (as opposed to //D in
> Interix 2.2).

I've tried with the both notations and the problem is the same.

Eljay wrote:

> Are you sure that your "//D/tst.log" exists before you run the
> program?

No, this file doesn't exist. But with previous versions of g++, if the file
didn't exist, it was created by the 'new fstream'.

Eljay wrote:

> Note, "r+" requires the file to be pre-existing.  Likewise with fstream.

> If you want to open the file if it exists for read/write, or create the
file for read/write if it doesn't exist, you'll have to code
> that into your routine.

So I've adapted my code. I first check if my file exists and if not I create
it with a "f.open(filename, ios::out)" (See code below).

-------------------------------------------------

#include <stdio.h>
#include <iostream.h>
#include <fstream.h>

int main(void)
{
   fstream *f;
   fstream ftst;
   char filename[256];

   sprintf(filename,"//D/tst.log");
   ftst.open(filename,ios::in);
   if(!ftst.good())
   {
      ftst.close();
      ftst.open(filename,ios::out);
   }
   ftst.close();
   
   f = new fstream(filename, ios::in | ios::out );

   if(f->good())
      printf("f ok\n");
   else
      printf("f nok\n");

   return 0;
}

-------------------------------------------------

Thank you for your help,
Hervé.
+-+-+- Email Confidentiality Footer +-+-+- 
Privileged/Confidential Information may be contained in this message. If you
are not the addressee indicated in this message (or responsible for delivery
of the message to such person), you may not print, retain, copy nor
disseminate this message or any part of it to anyone and you should notify
the sender by reply email and destroy this message. Neglecting this clause
could be a breach of confidence. Please advise immediately if you or your
employer does not consent to Internet email for messages of this kind.
Opinions, conclusions and other information in this message that are not
related to the official business of my firm shall be understood as neither
given nor endorsed by it.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]