Re: iostreams equivalent to C's fopen "r+"

From: Dave O'Hearn (daveoh77_at_pobox.com)
Date: 11/18/03


Date: 18 Nov 2003 13:25:10 -0800


"Chuck McDevitt" <Chuck_McDevitt@c-o-m-c-a-s-t.net> wrote:
> You are obviously on Windows. As far as I know, it's implementation
> defined if the file gets created or not.
> In the Windows implementation it does, on most Unix systems it does not.
>
> Windows has a ios::_Nocreate you can set.

I have two systems, a Red Hat 6.2 with gcc 2.95.3, and a Red Hat 9
with gcc 3.2.2. The ancient system has an ios::nocreate, and it's
definately creating the files unless I put ios::nocreate in there. I
don't know what the newer system does by default, but it has no
ios::nocreate, so I can't put that in my code without conditional
compilation, or it won't compile on Red Hat 9 at all.

I think I have to use the hack I found online, where you open for 'in'
mode first, then if it succeeds, reopen for in|out mode. It's odd that
'nocreate' isn't standard, since it's easy enough for a library to
fake even if the OS doesn't support it... and if the library doesn't
fake it, all the user code has to fake it instead. But that didn't
happen, so I will just have to fake it myself, oh well. Thanks.

-- 
Dave O'Hearn


Relevant Pages

  • Re: iostreams equivalent to Cs fopen "r+"
    ... >> mode first, then if it succeeds, reopen for in|out mode. ... >> fake it, all the user code has to fake it instead. ... finds nothing but default parameters in declarations, ... terse table describing the 6 openmode flags, ...
    (comp.lang.cpp)
  • Re: iostreams equivalent to Cs fopen "r+"
    ... > I think I have to use the hack I found online, ... > mode first, then if it succeeds, reopen for in|out mode. ... > fake it, all the user code has to fake it instead. ...
    (comp.lang.cpp)