C++小程序——定时关机

自己写的C语言小程序

源码如下:

#include<windows.h>
#include<iostream>
#include<cstdlib>
#include<cstdio>
using namespace std; 
int main() {
  int h, m, s;
  char c;
  cout << "\n\n\n           -------------------------------------------------------\n";
  cout << "           |                   是否关机?(Y/N):                  |\n";
  cout << "           -------------------------------------------------------\n";
  cout << "                               请输入:";
  c = getchar();
  if (c == 'Y' || c == 'y') {
    system("cls");
    cout << "\n\n\n           -------------------------------------------------------\n";
    cout << "           |         请输入多少时间后关机:(小时/分钟/秒)        |\n";
    cout << "           -------------------------------------------------------\n";
    cout << "                               请输入:";
    cin >> h >> m >> s; 
    system("cls"); 
    while(h || m || s) {
      cout << "\n\n\n           -------------------------------------------------------\n";
      cout << "           |                     距关机还有:                    |\n"; 
      cout << "           -------------------------------------------------------\n";
      cout << "                               " << h << "小时 " << m << "分钟 " << s << "秒" << endl;
      Sleep(1000);
      system("cls");
      if (s) --s;
      else if (!s && m) {
        s = 60;
        --m;
      }
      else if (!s && !m && h) {
        m = 60;
        s = 60;
        --h;
      }
    }
    system("shutdown -s -f -t 0");
  } 
  return 0;
}

百度云链接
链接: http://pan.baidu.com/s/1nvPPR7b
密码: qhuw

ps:如果没用的话,说明你的环境变量Path少了变量值(;C:\WindowsSystem32)不含括号,添加之后到C:\Windows\System32中找到shutdown.exe运行下即可使用本程序

原创帖,转载标明出处


版权声明:本文为aston5128原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。