>  기사  >  백엔드 개발  >  C/C++에서 system()을 사용할 때 놀라운 점은 무엇입니까?

C/C++에서 system()을 사용할 때 놀라운 점은 무엇입니까?

王林
王林앞으로
2023-08-29 11:29:021246검색

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

여기서 C 또는 C++에서 system() 함수를 사용하면 놀라운 결과를 볼 수 있습니다. 이 시스템 기능은 Windows, Linux 및 MAC 운영 체제에 있습니다. 이 함수는 명령줄에 작성할 수 있는 시스템 명령을 실행하는 데 사용됩니다.

여기에서는 C 또는 C++에서 시스템 기능의 두 가지 용도를 살펴보겠습니다. 첫 번째는 C++ 프로그램을 사용하여 IP 구성 세부 정보를 얻는 것입니다.

Example

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

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

두 번째가 더 흥미롭습니다. 이를 사용하여 컴퓨터를 종료할 수 있습니다. 시스템 기능에 종료 프로그램의 경로만 작성하면 됩니다.

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

출력

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

위 내용은 C/C++에서 system()을 사용할 때 놀라운 점은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제