首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::system

Defined in header <cstdlib>

int system( const char* command );

调用主机环境%27s命令处理器%28/bin/sh,,,cmd.exe,,,command.com%29,参数为command返回实现定义的值%28,通常是被调用的程序返回%29的值。

如果command是一个空指针,检查主机环境是否有命令处理器,并且只有当命令处理器存在时才返回非零值。

参数

command

-

character string identifying the command to be run in the command processor. If a null pointer is given, command processor is checked for existence

返回值

实现-定义的值。如果command为空指针,只有在命令处理器存在时才返回非零值。

注记

在POSIX系统上,返回值可以用WEXITSTATUS和WSTOPSIG...

相关POSIX函数波芬生成的输出command打电话的人可以用。

二次

代码语言:javascript
复制
#include <cstdlib>
#include <fstream>
#include <iostream>
 
int main()
{
    std::system("ls -l >test.txt"); // execute the UNIX command "ls -l >test.txt"
    std::cout << std::ifstream("test.txt").rdbuf();
}

二次

可能的产出:

二次

代码语言:javascript
复制
total 16
-rwxr-xr-x 1 2001 2000 8859 Sep 30 20:52 a.out
-rw-rw-rw- 1 2001 2000  161 Sep 30 20:52 main.cpp
-rw-r--r-- 1 2001 2000    0 Sep 30 20:52 test.txt

二次

另见

C系统文件

*。

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券