Is it possible to output a variable as a cmd command from a c++ program -
im making simple command line program c++ knowledge basic level, send command c++ program cmd made of part of command , rest variable here code far:
#include <iostream> #include <stdlib.h> using namespace std; int main() { string directory; cout<<"input directory make folder in: "; cin>> directory; system("mkdir" directory); }
i error:
error: expected ')' before 'directory'|
does know way of doing this? in end cmd execute command "mkdir c:*inputted directory*
i have hacked around trying work out, no success, have had on internet no avail, in advance.
rather call out shell use _mkdir
(for windows) or mkdir
(for linux) function instead:
_mkdir(directory.c_str());
for windows you'll need #include <direct.h>
, linux you'll need #include <sys/stat.h>
, #include <sys/types.h>
Comments
Post a Comment