Xan Nava Xan Nava - 3 months ago 36
C++ Question

c++ - _mkdir giving false errors windows

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

header

#include <direct.h>


script

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

try
{
_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;
}
return;
}
}


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

Answer

_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.