Shut Down Computer using C++ : To shutdown and restart you computer using C++ programming, just call the function system() of stdlib.h library which will call the cmd or terminal. So to shutdown and restart your computer, just place your code (including full path) to shutdown and restart your computer.
C++ Program to Shutdown & Restart Computer
#include <stdio.h>
#include <stdlib.h>
using namespace std;
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"); //c++ shutdown
return 0;
}
To shutdown Ubuntu or Linux based machines
#include <stdio.h>
int main()
{
system("shutdown -P now");
return 0;
}
Try with your Computer.Hope you like This.Thank You.