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

标签 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;
}

最佳答案

连接两者,然后使用c_str()std::string中获取C字符串:

system(("start " + app).c_str());

关于c++ - 如何将 C++ 变量数据放入 system() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41242820/

相关文章:

c++ - 奇怪的临时数组损坏

c++ - 2D 粒子系统 - 性能

我们可以使用为 32 位编译的应用程序调用为 64 位编译的 DLL 的函数吗?

c++ - 无法通过 C++ 警告 : (& crash after) deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

c++ - 在代码块中运行发布版本时出现段错误,但运行调试版本时不会出现段错误

c++ - OpenCV - 如何使用蒙版将图像的一部分复制到另一个图像?

php - 将图像解析为数据[任何语言]

java - Selenium/Java 无法与 Windows 上的 IE 一起使用

windows - 是否需要 FlushFileBuffers 才能跨多个进程同步文件数据?

c++ - 对符号的 undefined reference ,即使库已链接