Is there any way to retrieve the filename given to a std::ofstream
(passed in constructor or in ofstream::open( ))?
Or, should I derive from ofstream (should probably be a template to
handle ifstream and fstream as well, but I'm typing on the fly)
yes, I know the syntax may be off...
class onamedfstream : public ofstream {
private:
std::string filename_;
public:
ofnamedstream() : ofstream() { }
ofnamedstream(c onst char * fname, ios_base::openm ode mode =
ios_base::out) :
filename_(fname ), ofstream(fname, mode) { }
~ofnamedstream( ) { }
void open(const char *fname, ios_base::openm ode = ios_base::out)
{
filename_ = fname;
ofstream::open( fname, mode);
}
const std::string& get_filename(vo id) const { return filename_; }
};
Comment