c++ - 如何在系统 ("say string variable"中使用字符串变量)?

标签 c++ system-calls

/* 我想过这样做,但是无效。 所以任何帮助将不胜感激。 */

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int main()
{
   string name = "Karma";
   string greet = "How was your day?";
   string sums = name + greet;

   system("say %s", sums) // not working
   // system("say sums")  not working

   return 0;
}

最佳答案

您可以使用:

system(("say" + sums).c_str())

代替:

system("say %s", sums)

关于c++ - 如何在系统 ("say string variable"中使用字符串变量)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46995328/

相关文章:

c++ - 将成员函数作为参数传递给优化器(将成员函数传递给函数)

c - 如何在 Linux 上重新实现(或包装)系统调用函数?

java - 从 java 设置 ulimit -n

concurrency - 根据 POSIX,我的写入何时对其他进程可见?

user-interface - 使用系统调用的 Common Lisp GUI 编程

c++ - 将结构数组的元素复制到另一个相同类型的结构

c++ - 无法使用对类型键设置映射值

kernel - 在英特尔SGX中禁用syscall意味着什么

c++ - 如何将过程/函数值获取到最终程序中?

c++ - 组织 C++ 代码