首頁  >  文章  >  後端開發  >  在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設定詳細資訊。

範例

#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.

以上是在C / C++中使用system()的令人驚訝的東西是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除