Jack Klein <ja*******@spamcop.net> wrote:
On some platforms, a single file may have
more than one name.
.... or none at all:
std::ofstream tmpfile("mytempfile");
std::remove("mytempfile");
This is fine eg. on POSIX platforms and, except for the use of the hardcoded
name, a pretty common technique to create temporary files which are to be
removed when the program dies for whatever reason.
Of course you could always build an object that contained a
std::string with the name and a stream reference.
.... or attach the name to your file object:
int const index = std::ios_base::xalloc();
std::string filename("file.name");
std::ofstream file(filename.c_str());
file.pword(index) = const_cast<char*>(filename.c_str());
// ...
char const* name = static_cast<char*>(file.pword(index));
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>