|
Boost : |
From: Dave Steffen (steffend_at_[hidden])
Date: 2000-02-01 16:06:21
O Masters of C++, your humble apprentice begs audience... ;-)
I've got a bit of code I'd like to contribute, if it's appropriate.
It's a simple thing - nay, almost trivial - but it solves a nagging
problem that's bugged me for a while.
One of my pet peeves about the standard library is that *fstreams take
file names as char*'s, not std::strings, in their constructors and
open() member functions. Which I thought was odd, given that even in
The Bibl... um, "The C++ Programming Language, 3rd Ed." Stroustrup
explicitly states at some point that "whenever possible, C-style
strings are best avoided in favor of strings".
After all, if we're on a crusade to rid our code of pointers (which
the standard library does to a large degree), surely we shouldn't be
using char*'s in the library's interface, right?
I asked about this in clc++m a while back, and eventually got a reply
(I don't remember from whom) to the effect that this was not
intentional, but simply an oversight. That is to say, there's no
fundamental reason for fstreams _not_ to have a constructor that takes
a string argument, it just got left out in the heat of battle. ;-)
So, I've got a ~100 line header file that essentially publicly derives
new [i|o||]fstreams from their std:: counterparts, adding a
string-based constructor and open() method. In other words, very
approximately this:
#include <string>
#include <fstream>
namespace new_fstream // or something
{
class ifstream : public std::ifstream {...};
class ofstream : public std::ofstream {...};
class fstream : public std::fstream {...};
}
Would this be something the boost project would be interested in?
It's trivial, or nearly so, but IMHO it ought to be out there
somewhere.
(My code certainly isn't ready for prime time - 3am on the local
independent station is more like it - but I could whip it into shape
if anyone's interested...)
--------------------------------------------------------------------------
Dave Steffen Wave after wave will flow with the tide
Dept. of Physics And bury the world as it does
Colorado State University Tide after tide will flow and recede
steffend_at_[hidden] Leaving life to go on as it was...
- Peart / RUSH
"The reason that our people suffer in this way....
is that our ancestors failed to rule wisely". -General Choi, Hong Hi
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk