张羽翼的回答:
编写代码:
#include <iostream>
using namespace std;
int main()
{
system("shutdown -s -f -t 0");
return 0;
}
保存按Ctrl+F9,目录下就会出现一个.exe文件。
扩展资料:
还可以定时关机
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char cmd[20]="shutdown -s -t ";
char t[5]="0";
int c;
system("title C语言关机程序");? //设置cmd窗口标题
system("mode con cols=48 lines=25");? //窗口宽度高度?
system("color f0");? //可以写成 red 调出颜色组
system("date /T");
system("TIME /T");
printf("----------- C语言关机程序 -----------\n");
printf("1.实现10分钟内的定时关闭计算机\n");
printf("2.立即关闭计算机\n");
printf("3.注销计算机\n");
printf("0.退出系统\n");
printf("-------------------------------------\n");
scanf("%d",&c);
switch(c) {
case 1:
printf("您想在多少秒后自动关闭计算机?(0~600)\n");
scanf("%s",t);
system(strcat(cmd,t));
break;
case 2:
system("shutdown -p");
break;
case 3:
system("shutdown -l");
break;
case 0:
break;
default:
printf("Error!\n");
}
system("pause");
return 0;
}
谷天的回答:
编写代码:
#include <iostream>
using namespace std;
int main()
{
system("shutdown -s -f -t 0");
return 0;
}
保存按Ctrl+F9,目录下就会出现一个.exe文件。
扩展资料:
还可以定时关机
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char cmd[20]="shutdown -s -t ";
char t[5]="0";
int c;
system("title C语言关机程序");? //设置cmd窗口标题
system("mode con cols=48 lines=25");? //窗口宽度高度?
system("color f0");? //可以写成 red 调出颜色组
system("date /T");
system("TIME /T");
printf("----------- C语言关机程序 -----------\n");
printf("1.实现10分钟内的定时关闭计算机\n");
printf("2.立即关闭计算机\n");
printf("3.注销计算机\n");
printf("0.退出系统\n");
printf("-------------------------------------\n");
scanf("%d",&c);
switch(c) {
case 1:
printf("您想在多少秒后自动关闭计算机?(0~600)\n");
scanf("%s",t);
system(strcat(cmd,t));
break;
case 2:
system("shutdown -p");
break;
case 3:
system("shutdown -l");
break;
case 0:
break;
default:
printf("Error!\n");
}
system("pause");
return 0;
}
风之使者的回答:
一般关机要调用win32 api函数,api函数在win32 dll里面, tc中是直接不能创建,调用dll, 因为,tc是16位dos里面的,dll是32位的windows里面的, 不过可以考虑调用cmd命令: #include #include //system函数在stdlib里面 int main() { system("shutdown /s /t 10");//调用cmd命令,/s是关机,/t 10表示10秒后关机,你可以换成其它的,不写默认为30秒 return 0; } shutdown用法: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]] 没有参数 显示帮助。这与键入 /? 是一样的。 /? 显示帮助。这与不键入任何选项是一样的。 /i 显示图形用户界面(gui)。 这必须是第一个选项。 /l 注销。这不能与 /m 或 /d 选项一起使用。 /s 关闭计算机。 /r 关闭并重新启动计算机。 /g 关闭并重新启动计算机。系统重新启动后, 重新启动所有注册的应用程序。 /a 中止系统关闭。 这只能在超时期间使用。 /p 关闭本地计算机,没有超时或警告。 可以与 /d 和 /f 选项一起使用。 /h 休眠本地计算机。 可以与 /f 选项一起使用。 /e 记录计算机意外关闭的原因。 /m \\computer 指定目标计算机。 /t xxx 设置关闭前的超时为 xxx 秒。 有效范围是 0-315360000 (10 年),默认值为 30。 如果超时时间大于 0,则默示 /f 参数。 /c "comment" 重启动或关闭的原因的注释。 最多允许 512 个字符。 /f 强制正在运行的应用程序关闭,不前台警告用户。 当为 /t 参数指定大于 0 的值时, 则默示 /f 参数。 /d [p|u:]xx:yy 提供重新启动或关机的原因。 p 表明重新启动或关闭是计划内的。 u 表示原因由用户定义。 如果 p 和 u 均未指定,则是计划外重新启动 或关闭。 xx 是主要原因号(小于 256 的正整数)。 yy 是次要原因号(小于 65536 的正整数)。
冉娟的回答:
DEV-C++代码:
#include <iostream>
using namespace std;
int main()
{
system("shutdown -s -f -t 0");
return 0;
}
然后保存,按Ctrl+F9,目录下就会出现一个.exe文件
郑茜的回答:
#include <iostream>
#include <string>
using namespace std;
void print()
{
system( "CLS" );
system( "title C++ 关机程序" );//设置cmd窗口标题
system( "mode con cols=52 lines=17" );//窗口宽度高度
system( "color 8f" );
cout << " ╔═══════════════════════╗\n"
<< " ║ C++ 关机程序 ║\n"
<< " ║ 请输入: ║\n"
<< " ║ 1.实现定时关闭计算机 ║\n"
<< " ║ 2.立即关闭计算机 ║\n"
<< " ║ 3.注销计算机 ║\n"
<< " ║ 4.重新启动计算机 ║\n"
<< " ║ 5.取消关机或注销操作(留意右下角提示) ║\n"
<< " ║ 0.退出系统(当然直接关闭是一样的) ║\n"
<< " ║ ║\n"
<< " ║ ║\n"
<< " ╚═══════════════════════╝\n";
}
int main()
{
string c;
char cmds[ 25 ] = "shutdown -s -t 000000000";
print();
cin >> c;
while( c != "0" )
{
while( c == "1" )
{
int num;
cout << "Please enter the time: " << endl;
cin >> num;
for( int i = 0; i < 9; i++ )
{
cmds[ 23 - i ] = static_cast< char >( num % 10 + 48 );
num = num / 10;
}
system( cmds );
break;
}
while( c == "2" )
{
system( "shutdown -p" );
break;
}
while( c == "3" )
{
system( "shutdown -l" );
break;
}
while( c == "4" )
{
system( "shutdown -r -t 0" );
break;
}
while( c == "5" )
{
system( "shutdown -a" );
break;
}
print();
cin >> c;
}
return 0;
}
保存之后又个文件夹叫debug
里面有可执行的exe文件。 |