C++ 在system()函数(Mac)中获取输入 #包括 使用名称空间std; int main(){ 短内关; 不能进入; 系统(“说“%d”)
您必须转义引号并格式化字符串。另一种方法是:C++ 在system()函数(Mac)中获取输入 #包括 使用名称空间std; int main(){ 短内关; 不能进入; 系统(“说“%d”),c++,macos,bash,system,C++,Macos,Bash,System,您必须转义引号并格式化字符串。另一种方法是: #include <iostream> using namespace std; int main() { short int enterVal; cout << "enter a number to say: " << endl; cin >> enterVal; system("say "%d"") << enterVal; return 0
#include <iostream>
using namespace std;
int main() {
short int enterVal;
cout << "enter a number to say: " << endl;
cin >> enterVal;
system("say "%d"") << enterVal;
return 0;
}
#包括
#包括
使用名称空间std;
int main(){
短内关;
char命令[128];
不能进入;
snprintf((char*)&命令,128,“say\%d\”,enterVal);
系统(指挥部);
返回0;
}
您还应该注意,您应该以编程方式避免使用system()调用,因为这会使您的程序容易受到安全漏洞的攻击
如果你只是在胡闹,不介意,那就千方百计继续;)你必须去掉引号并格式化字符串。另一种方法是:
#include <iostream>
using namespace std;
int main() {
short int enterVal;
cout << "enter a number to say: " << endl;
cin >> enterVal;
system("say "%d"") << enterVal;
return 0;
}
#包括
#包括
使用名称空间std;
int main(){
短内关;
char命令[128];
不能进入;
snprintf((char*)&命令,128,“say\%d\”,enterVal);
系统(指挥部);
返回0;
}
您还应该注意,您应该以编程方式避免使用system()调用,因为这会使您的程序容易受到安全漏洞的攻击
如果您只是在胡闹,不介意,那么请务必继续;)您必须手动格式化字符串
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
short int enterVal;
char command[128];
cout << "enter a number to say: " << endl;
cin >> enterVal;
snprintf((char *)&command, 128, "say \"%d\"", enterVal);
system(command);
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
短内关;
cin>>企业;
细流ss;
ss您必须手动格式化字符串
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
short int enterVal;
char command[128];
cout << "enter a number to say: " << endl;
cin >> enterVal;
snprintf((char *)&command, 128, "say \"%d\"", enterVal);
system(command);
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
短内关;
cin>>企业;
细流ss;
ss您可以使用以下内容:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
short int enterVal;
cin >> enterVal;
stringstream ss;
ss << "say \"" << enterval << "\"";
system(ss.str().c_str());
}
#包括
#包括
使用名称空间std;
int main(){
短内关;
不能进入;
ostringstream浅黄色;
buff您可以使用以下内容:
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
short int enterVal;
cin >> enterVal;
stringstream ss;
ss << "say \"" << enterval << "\"";
system(ss.str().c_str());
}
#包括
#包括
使用名称空间std;
int main(){
短内关;
不能进入;
ostringstream浅黄色;
buff是的,这个节目只是为了好玩。:)是的,这个节目只是为了好玩。:)