TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: HERBERT BUSHONG
from: JERRY COFFIN
date: 1997-08-11 19:13:00
subject: fstream identifying mode

On (08 Aug 97) Herbert Bushong wrote to All...
 HB> Is there a way to identify the mode that an fstream was opened in?
 HB> (binary vs. text -- borland 4.5)
None of which I'm aware, but fortunately, it shouldn't be terribly
difficult to add the capability yourself:
class my_stream : public fstream {
    int mode_;
public:
    my_stream() : mode_(0), fstream() {}
    my_stream(ÿconstÿchar*ÿname, intÿmode) :
        fstream(name, mode), mode_(0) {}
    my_stream(ÿfiledescÿfdÿ) :
        fstream(fd), mode_(0) {}
    my_stream(ÿfiledescÿfd, char*ÿbuffer, intÿlengthÿ) :
        fstream(fd, buffer, lengt) , mdoe_(0) {}
    voidÿopen(ÿconstÿchar*ÿname, intÿmode) :
        mode_(mode)
    {
        fstream::open(name, mode);
    }
    int mode() {
        return mode_;
    }
};
You may have to add a few more things to this; for example, I believe
Borland supports a third parameter that determines the sharing allowed
with the file, and you may want to support that as well.  Likewise, you
might have to get a bit more sophisticated with things: it's possible
that one of the constants for opening is actually 0, in which case you
might want to do something like keep track of whether the stream is
open to determine what sort of thing to return from mode().
    Later,
    Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.