c++中system函数不能用变量吗?

比如:system("shutdown -s -t %d",time)不能运行,新手,刚自学完基本循环,什么都不懂,谁会的话请指教,就是想输入一个关机倒计时的时间,该怎么做呢?不用这个函数也行……

system函数只有一个参数!

/////////////////////////////////////////
// C-Free 4.1
// MinGW 3.4.5
// veket的小号
/////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int time = 60;
char str[100] = "shutdown -s -t ";
sprintf(str+strlen(str), "%d\0", time);
printf("用system函数调用shutdown命令倒计时关机\n");
printf("解除方法:打开cmd 输入命令shutdown -a\n");
system(str);
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-12-17
这个就和你在运行里输入的一样。
第2个回答  2012-12-17
char cmd[128];
sprintf(cmd , "shutdown -s -t %d",time" );
system(cmd);
第3个回答  2012-12-17
shutdown -s -t %d",time
相似回答