Home > Backend Development > C++ > What's the amazing thing about using system() in C/C++?

What's the amazing thing about using system() in C/C++?

王林
Release: 2023-08-29 11:29:02
forward
1337 people have browsed it

在C / C++中使用system()的令人惊奇的东西是什么?

Here we will see some amazing results by using the system() function in C or C. This system feature is present in Windows, Linux and MAC operating systems. This function is used to execute system commands that can be written in the command line.

Here we will see two uses of system functions in C or C. The first is to use a C program to get the IP configuration details.

Example

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
   system("C:\Windows\System32\ipconfig");
}
Copy after login

Output

Windows IP Configuration
Ethernet adapter Local Area Connection:
   Connection-specific DNS Suffix . : domain.name
   Link-local IPv6 Address . . . . . : fe80::302b:9dff:1cfb:ff01%10
   IPv4 Address. . . . . . . . . . . : 192.168.2.6
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::217:7cff:fe3d:31c8%10
                                       192.168.2.1
Ethernet adapter VirtualBox Host-Only Network:
   Connection-specific DNS Suffix . :
   Link-local IPv6 Address . . . . . : fe80::5c79:a124:f5b9:e0b7%13
   Autoconfiguration IPv4 Address. . : 169.254.224.183
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
Ethernet adapter VirtualBox Host-Only Network #2:
   Connection-specific DNS Suffix . :
   Link-local IPv6 Address . . . . . : fe80::7c54:289:9257:dd7a%16
   IPv4 Address. . . . . . . . . . . : 192.168.243.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :
Tunnel adapter Teredo Tunneling Pseudo-Interface:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix . :
Tunnel adapter isatap.{E12FA520-1578-4264-A565-A1270D18177A}:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix . :
Tunnel adapter isatap.{A01195C5-0A34-4E50-89CB-4C391165B7C3}:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix . :
Tunnel adapter isatap.domain.name:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix . : domain.name
Copy after login

The second one is more interesting. Using this, we can shut down the computer. We only need to write the path of the shutdown program in the system function.

Example

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
   system("C:\WINDOWS\System32\shutdown /s");
}
Copy after login

Output

One box will appear. It will tail the system is shutting down, then it will be shut down.
Copy after login

The above is the detailed content of What's the amazing thing about using system() in C/C++?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template