title: How to create directory c++ (using _mkdir)
body: <p>Today I did a lot of research online about how to create a directory on C++
  and found a lot of way to do that, some easier than others.</p>
  
  <p>I tried the <code>_mkdir</code> function using <code>_mkdir("C:/Users/...");</code> to create a folder. Note that the argument of function will be converted into a <code>const char*</code>. </p>
  
  <p>So far, so good, but when I want to change the path, it does not work (see the code below). I have a default string path <code>"E:/test/new"</code>, and I want to create 10 sub-folders: <code>new1</code>, <code>new2</code>, <code>newN</code>, ..., <code>new10</code>. </p>
  
  <p>To do that, I concatenate the string with a number (the counter of the <code>for</code>-loop), converted into char using <code>static_cast</code>, then I transform the string using <code>c_str()</code>, and assign it to a <code>const char*</code> variable. </p>
  
  <p>The compiler has no problem compiling it, but it doesn't work. It prints 10 times <em>"Impossible create folder n"</em>. What's wrong? </p>
  
  <p>I probably made a mistake when transforming the string using <code>c_str()</code> to a get a <code>const char*</code>?. </p>
  
  <p>Also, is there a way to create a folder using something else? I looked at <code>CreateDirectory();</code> (API) but it uses keyword like <code>DWORD HANDLE</code>, etc., that are a little bit difficult to understand for a no-advanced level (I don't know what these mean).</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  #include&lt;direct.h&gt;
  
  using namespace std;
  
  int main()
  {
  int stat;
  string path_s = "E:/test/new";
  
  for (int i = 1; i &lt;= 10; i++)
  {
      const char* path_c = (path_s + static_cast&lt;char&gt;(i + '0')).c_str();
      stat = _mkdir(path_c);
  
      if (!stat)
          cout &lt;&lt; "Folder created " &lt;&lt; i &lt;&lt; endl;
      else
          cout &lt;&lt; "Impossible create folder " &lt;&lt; i &lt;&lt; endl;
      Sleep(10);
  }
  return 0;
  }
  </code></pre>