Computer >> 컴퓨터 >  >> 프로그램 작성 >> C 프로그래밍

C/C++에서 system()으로 놀라운 일?

<시간/>

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

여기에서는 시스템이 C 또는 C++에서 작동하는 경우 두 가지 사용법을 볼 수 있습니다. 첫 번째는 C++ 프로그램을 사용하여 IP 구성 세부 정보를 가져오는 것입니다.

예시

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

출력

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.