一个简单的C++程序

[复制链接]
查看11 | 回复4 | 2009-2-12 22:34:15 | 显示全部楼层 |阅读模式
请帮改下面的程序,要用纯C++的,目的是使之可以输入a的值制定关机时间.最好能帮我补充个恢复程序.谢谢!
#include
#include
int main()
{
int a;
cout>a;
system("shutdown -s -t a"); //为什么里面的a改为数字才行呢,而调用a不行
return 0;
}

回复

使用道具 举报

千问 | 2009-2-12 22:34:15 | 显示全部楼层
你真强悍,C++编译器还没自动化到把双引号引起的字符串中的a替换为你的int值.用一个字符串来生成shutdown命令,再调用system执行吧.
shutdown -s -t是关机,shutdown -a是撤销关机...
回复

使用道具 举报

千问 | 2009-2-12 22:34:15 | 显示全部楼层
system("shutdown -s -t a");因为system("");中" "类是 字符串如果用system("shutdown -s -t a");shutdown -s -t a不能代表shutdown -s -t 60(假如a=60)就像这样int a=5;cout #include #includeint main() { int a; cout>a; char order[30];sprintf(order,"shutdown -s -t %d",a);syst...
回复

使用道具 举报

千问 | 2009-2-12 22:34:15 | 显示全部楼层
include#includeint main() { int a; cout>a;system(string.Format("shutdown -s -t %d",a));return 0; }...
回复

使用道具 举报

千问 | 2009-2-12 22:34:15 | 显示全部楼层
试试这样行不行。system("shutdown -s -t %d",a);...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行