Problem with fstream.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi,
> 
> I'm using g++ 3.3 on SFU3.5.
> I want to run the following example:
> 
> ----------------------------------------
> #include <stdio.h>
> #include <iostream.h>
> #include <fstream.h>
> 
> int main(void)
> {
>    fstream *f;
>    char filename[256];
> 
>    sprintf(filename,"//D/tst.log");
>    f = new fstream(filename, ios::in | ios::out);
> 
>    if(f->good())
>       printf("f ok\n");
>    else
>       printf("f nok\n");
> 
>    return 0;
> }
> -----------------------------------------------
> 
> I compile it with the "-Wno_deprecated" option.
> When I run it, the file isn't created, the f->good() returns false, and so
> I've a "f nok" on my screen.
> 
> When I compile and run it with g++ 2.? on Interix 2.2, the file is
> created, the f->good() returns true, and I've the "f ok".
> 
> I've tried to use the new header files (fstream, iostream), but the result
> is the same:
> 
> ------------------------------------------
> #include <iostream>
> #include <fstream>
> 
> int main(void)
> {
> 	std::fstream *f;
> 	char filename[256];
> 
> 	sprintf(filename,"//D/tst.log");
>         f = new std::fstream(filename, std::ios::in | std::ios::out );
> 
>         if((f->good()) )
>            printf("f ok\n");
>         else
>            printf("f nok\n");
> 
>    return 0;
> }
> ------------------------------------------
> 
> If for the new, I don't use "ios::in | ios::out" but I use "ios::out", my
> program works and create the file (but I need the "ios::in | ios::out" in
> my true application).
> 
> Is there something that I make wrong? Is it a known problem? Is there a
> workaround?
> 
> Thanks in advance,
> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux