I implemented a solution to the problem meant to be cross-platform and adherent to the C++ standard library.
bool isdir(const char *string) {
ofstream file(string, ios::out);
return file.fail();
}
Yet, if the file is actually writable, the program opens an empty file with string name in its working directory.
How can I prevent this from happening?
There is no standard way of detecting if a file is a directory in C++. But you can use Boost.Filesystem. It is well portable.
Edit: It seems that this question has already been answered here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With