I know that the question has been answered already, but I wanted to share another approach to this, and it's too verbose for a comment :)
short example:
#include <cstdio>
#include <cstdlib>
int main()
{
char x[] = "yourdirectory";
/* len will contain the length of the string that would have been printed by snprintf */
int len = snprintf(0, 0, "mkdir %s", x);
/* casting the result of calloc to (char*) because we are in C++ */
char *buf = (char*)calloc(len + 1, sizeof(char));
/* fail if the allocation failed */
if(!buf)
return -1;
/* copy to buffer */
snprintf(buf, len + 1, "mkdir %s", x);
/* system is evil :( */
system(buf);
return 0;
}
since snprintf returns the number of characters that would have been printed, giving it a length of 0 will tell you how large a buffer you have to allocate for the command.
this code will also work with arbitrary directories given by a user and will not suffer from input truncation of buffer overruns.
Take care :)
EDIT: of course, system is still evil and should never be used in "real" code ;)