Recognize file type in C ++

I have implemented a solution to a problem that needs to be cross-platform and compatible with the standard C ++ library.

bool isdir(const char *string) {
   ofstream file(string, ios::out);
   return file.fail();
}

However, if the file is actually writable, the program opens an empty file with a name stringin its working directory. How can I prevent this?

+3
source share
1 answer

There is no standard way to determine if a file is a C ++ directory. But you can use Boost.Filesystem . It is well tolerated.

Edit: It seems that this question has already been answered here .

+4
source

All Articles