0

I have the following code:

string name;
getline(cin,name);
ofstream foldercreator(name + "folder.bat");
foldercreator << "if not exist \"" << name << "\" mkdir " << name << endl;
foldercreator << "exit";

The problem is, that

string batname = "start " + name + "folder";
system(batname);
system("start " + name + "folder");

doesn't work either.

The only problem is, that it cannot open the file.

  • system is a `C` function. Use `system( batname.data() );`. In any case - I think your are looking for [boost process](https://stackoverflow.com/questions/49652210/kill-my-process-if-the-other-process-is-killed/49652550#49652550) – Victor Gubin Nov 18 '20 at 16:31

1 Answers1

2

You can use std::string::c_str() to obtain a pointer to C string from std::string.

string batname = "start " + name + "folder";
system(batname.c_str());
system(("start " + name + "folder").c_str());
MikeCAT
  • 73,922
  • 11
  • 45
  • 70