RS> RS>> You have to open the file before you can write to it.
RS>
RS> TM> No. The ofstream constructor does that.
RS>
RS> Oh, really? I don't doubt it can be done, but is that the
RS> default or does that have to be implemented by you?
RS>
RS> RS>> TM> }
RS>
RS> RS>> And close it when you're done
RS>
RS> TM> No. The ofstream destructor does that.
RS>
RS> Sounds like sloppy programming to me, but then I'm very new
RS> to the C++. I feel that IO cleanup should be done explicitly.
RS>
Actually, this is quite within the spirit of C++. In fact, doing
anything else is considered sloppy programming by some people, including
Bjarne Stroustrup, the original designer of C++! In fact, if you do
your cleanup explicitly instead of within the destructors you run the
risk of resource leaks. If you use exception handling, which IS part of
the C++ specification, you run a CERTAINTY of resource leaking! Most if
not all libraries use exception handling today, so in fact you are using
it whether you like it or not. Furthermore the ANSI C++ standard
specifies throwing exceptions in the standard library so there you are!
I ask that you refer to the following reference :
"The C++ Programming Language", 1997, pp. 366 - 7.
by Bjarne Stroustrup
Those two pages give a good description as to why what you call
"sloppy programming" is in fact an excellent technique to be
encouraged as much as possible!
Thanks,
Peter
---
þ KWQ/2 1.2i þ We've secretly replaced the DiLithium with new Folgers
Crystals..
---------------
* Origin: St. Louis Users Group (1:100/4)
|