如何将c ++变量数据放入system()函数

Jim*_*im. 2 c++ windows codeblocks

如何将c ++变量数据放入system()函数?

看下面的代码:

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
  cout << "name the app u want to open";

  string app;

  cin >> app;

  system("start app"); // I know this will not work! But how to make it will?
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

Som*_*ken 5

将两者连接起来,然后拿到C字符串出的std::string具有c_str():

system(("start " + app).c_str());
Run Code Online (Sandbox Code Playgroud)