I am writing a (hopefully) cross-platform application in C++. I need to create a directory. However it seems there is no standard interface in C++ to create a directory. A workaround I have come up with is to use the mkdir
command. mkdir
works in cmd
, Powershell
, and Bash
. I am hoping that this will address most cross-platform use cases. The code would be something like:
#include <cstdlib>
int main(int argc, char** argv) {
int errorCode = system("mkdir SOME_DIRECTORY");
if (errorCode != 0) {
// OOPS, SOMETHING WENT WRONG
}
else {
// ALL'S WELL THAT ENDS WELL
}
}
Is there a reason I should not take this approach? Are there other convenient alternatives for creating directories?