Mail Archives: djgpp/1998/11/22/08:53:35
sl wrote in message ...
> According to my trusty book here, ofstream defaults to using
>ios::trunc when opening file...
>
> Looking at the implementation I found the... constructor
>defaults "mode" to "ios::out" .. when I use ios::trunc in place and override
>the default, the file knows it should open in truncate mode, but it does not
>know to open in output mode. I believe this is an implementation fault: no
>matter what the programmer specifies, ofstream should ALWAYS use ios::out and
>when someone chooses to do
>
>ofstream someFile("hello.txt", ios::trunc);
>
> like me, it should know that really means ios::out|ios::trunc.. After
>all, that *is* the definition of the ofstream class. Any suggestions,
>comments?
I think you are correct. I think you are reporting it to the wrong
newsgroup, but I think you are correct :)
From the C++ standard working paper of Nov 97 obtained from
http://www.cygnus.com/ :
explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out);
Effects:
Constructs an object of class basic_ofstream<charT,traits>, initial-
izing the base class with basic_ostream(&sb) and initializing sb
with basic_filebuf<charT,traits>(), then calls rdbuf()->open(s, mode|out).
It is presumably that "|out" that gcc's libstdc++ is missing. You
should report it to the maintainers of that library in the way
recommended in the gcc info manual (if you want to).
Ian
--
Ian Miller, Dorset, UK
- Raw text -