首页 > 后端开发 > C++ > 正文

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

王林
发布: 2023-08-29 11:29:02
转载
1497人浏览过

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

在这里,我们将通过使用 C 或 C++ 中的 system() 函数看到一些令人惊奇的结果。该系统功能存在于Windows、Linux和MAC操作系统中。该函数用于执行可以在命令行中编写的系统命令。

这里我们将看到系统函数在C或C++中的两种用法。第一个是使用C++程序获取IP配置详细信息。

阿里云-虚拟数字人
阿里云-虚拟数字人

阿里云-虚拟数字人是什么? ...

阿里云-虚拟数字人 2
查看详情 阿里云-虚拟数字人

示例

#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中文网其它相关文章!

相关标签:
c++速学教程(入门到精通)
c++速学教程(入门到精通)

c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号