M
Matt
Hello,
I see other references in this newsgroup saying that the only standard
C++ way to test for file existence is some variant of my code below;
can someone please confirm...or offer alternatives?
Additionally, might there be cross-platform alternatives, say in a
library like Boost, or something else?
-Matt
#include <fstream>
/*
[class FileHandle contains 'fstream file' and previously-initialed
'string filename'.]
*/
bool
FileHandle::exists()
{
bool retval = false;
// TODO/XXX: Is there a better way to
// test the existence of a file
// without opening it?
file.open(filename.c_str(), ios::in | ios::binary);
if (!file.fail()) retval = true;
file.close();
return retval;
}
I see other references in this newsgroup saying that the only standard
C++ way to test for file existence is some variant of my code below;
can someone please confirm...or offer alternatives?
Additionally, might there be cross-platform alternatives, say in a
library like Boost, or something else?
-Matt
#include <fstream>
/*
[class FileHandle contains 'fstream file' and previously-initialed
'string filename'.]
*/
bool
FileHandle::exists()
{
bool retval = false;
// TODO/XXX: Is there a better way to
// test the existence of a file
// without opening it?
file.open(filename.c_str(), ios::in | ios::binary);
if (!file.fail()) retval = true;
file.close();
return retval;
}