2017-10-28 147 views
0

/*我想这样做,但它是无效的。 所以任何帮助将不胜感激。 */如何在系统中使用字符串变量(“say string variable”)?

#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; 
} 
+0

'系统(( “说” +资金).c_str());' – HolyBlackCat

+2

也“[为什么“使用命名空间标准”被认为是不好的做法?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)“。 – HolyBlackCat

+0

'system'接受一个指向常量字符串而不是'class string'的指针。 – Raindrop7

回答

2

您可以使用:

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

相反的:

system("say %s", sums) 
相关问题