Xan Nava Xan Nava - 1 year ago 144
C++ Question

c++ - _mkdir giving false errors windows

Hi I am trying to make a directory in windows with this code


#include <direct.h>


int main() {
string local = "C:/Program Files (x86)/Mail";

_mkdir (local.c_str ());
cout << "It is made?";

catch(invalid_argument& e)
cout << e.what () << " " << (char*) EEXIST;
if (e.what () == (char*) EEXIST) {
cout << e.what () << " " << (char*) EEXIST;

The file is clearly not made, but it is also not making the error it should.

Answer Source

_mkdir won't throw an exception. (This is not python or boost, or any smart middleware)

Read the documentation you were referring to: it returns a value. 0 is OK, -1: error, ask why to errno

Don't ignore the return value. You probably have insufficient rights without UAC elevation to create the directory.