I’m trying to make a program which will create a sum of directories the user wants to create.
this is my code:
#include <cstdlib>
#include <iostream>
#include<windows.h>
using namespace std;
int main(int argc, char *argv[]) {
int nrDirs = 0;
cin>> nrDirs;
for (int i = 0; i <= nrDirs; i++) {
CreateDirectory ("C:\\Users\\myName\\Desktop\\new", NULL);
}
system("PAUSE");
return EXIT_SUCCESS;
}
Now my problem, I don’t know how to rename the directory. I know how to do this in Objective-C:
"C:\\Users\\myName\\Desktop\\new%i", i
But this don’t work in c++. 🙁
So how do i do this?
Use can use
CString::Format:Use can use
std::stringstream:Use can use
sprintf:For all the above cases,
dirNameis a buffer that you will need to pass toCreateDirectory.If intermediate directories in the path do not exist, use
SHCreateDirectory. This API also creates intermediate directories in the path if they do not exist.