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

how can I use string variable in system("say string variable")?

本文关键字:字符串 变量 string 系统 say variable      更新时间:2023-10-16

/* 我想过这样做,但它无效。 因此,任何帮助将不胜感激。*/

#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)