<cstdlib>下system函数的使用

int system(const char* command)

调用系统命令执行command。如果command为空,返回处理器是否可用(0不可用)。

使用例子

#include <stdlib.h> //or #include <cstdlib>
system("dir");


这提供了与系统交互的接口,方便我们使用shell命令。

本人访问一个页面,本要使用curl,要设置很多参数,注意线程安全等,使用linux 的wget命令就方便多了。

string str="wget -q -O /dev/null http://www.baidu.com";
system(str.c_str());


补:cstdlib包含了c/c++最常用的系统函数,如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()

原文地址:https://www.cnblogs.com/whuqin/p/4982027.html