R
red floyd
Is there any way to retrieve the filename given to a std:fstream
(passed in constructor or in ofstream:pen())?
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(const char * fname, ios_base:penmode mode =
ios_base:ut) :
filename_(fname), ofstream(fname, mode) { }
~ofnamedstream() { }
void open(const char *fname, ios_base:penmode = ios_base:ut)
{
filename_ = fname;
ofstream:pen(fname, mode);
}
const std::string& get_filename(void) const { return filename_; }
};
(passed in constructor or in ofstream:pen())?
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(const char * fname, ios_base:penmode mode =
ios_base:ut) :
filename_(fname), ofstream(fname, mode) { }
~ofnamedstream() { }
void open(const char *fname, ios_base:penmode = ios_base:ut)
{
filename_ = fname;
ofstream:pen(fname, mode);
}
const std::string& get_filename(void) const { return filename_; }
};