Creating directory using string c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Creating directory using string c++

string username="Ali"; string path = "c:/Backup/total data/" + username; mkdir("c:/Backup"); mkdir("c:/Backup/total userdata"); mkdir(path.c_str()); // method does not work system(path.c_str()); // method does not work

4th Feb 2017, 11:26 AM
Zaka Ahmad Chishti
Zaka Ahmad Chishti - avatar
1 Answer
+ 1
are you checking if the first two mkdir() are succeeding? if they are failing then the 3rd mkdir will fail to. one more thing, you are making two different paths. total data and total userdata. these are different! unless you are forcing mkdir to create all subdirectories, the third mkdir IS going to fail. also that system call isn't doing anything. you'd need to pass a command like: string cmd = "mkdir"+ path; system (cmd.c_str());. // <-- this should work!
6th Feb 2017, 5:19 AM
M King
M King - avatar