2017-10-28 52 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) 
相關問題