Is there a C++ function to turn off the computer?

后端 未结 6 2249
悲&欢浪女
悲&欢浪女 2020-12-30 16:51

Is there a C++ function to turn off the computer? And since I doubt there is one (in the standard library, at least), what\'s the windows function that I can call from C++?

6条回答
  •  [愿得一人]
    2020-12-30 17:30

    yes! for Windows XP:

    #include 
    #include 
    
    int main()
    {
       char ch;
    
       printf("Do you want to shutdown your computer now (y/n)\n");
       scanf("%c", &ch);
    
       if (ch == 'y' || ch == 'Y')
           system("C:\\WINDOWS\\System32\\shutdown -s");
           return 0;
    }
    

    For Windows 7

    system("C:\\WINDOWS\\System32\\shutdown /s");
    

    For Linux

    system("shutdown -P now");
    

提交回复
热议问题