• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 01, 2022 |1.2K Views
C++ Program to Shutdown & Restart Computer
Description
Discussion

In this video, we will see how to write a a C++ program to shutdown & restart the computer.

A system() is used to invoke an operating system command from a C/C++ program.

Syntax: 
int system(const char *command);
 
Note: stdlib.h or cstdlib needs to be included in to call the system.

So by using system(), we can execute any command that can run on the terminal if the operating system allows it. For example, we can call system(“dir”) on Windows and system(“ls”) to list the contents of a directory.

Here we use switch case statements and the following commands for perform shutdown and restart operations:
/s /t - shutdown
/r /t - restart

Read More