从C ++程序调用linux命令 [英] call linux command from C++ program

查看:180
本文介绍了从C ++程序调用linux命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下简单的c ++程序,以了解如何从C ++程序调用Linux命令(通过使用系统命令)

I write the following simple c++ program in order to learn about how to call Linux command from C++ program (by using the system command)

请咨询为什么我有C ++编译器的错误?

Please advice why I have the errors from the C++ compiler? what wrong with my program?

#include <stdio.h>
#include <stdlib.h>
int main()
{
  system("echo -n '1. Current Directory is '; pwd");
  system("mkdir temp");
  system();
  system();
  system("echo -n '3. Current Directory is '; pwd");
  return 0;
  }


  [root@linux /tmp]# g++ -Wall  exm2.cc  -o exm2.end

  /usr/include/stdlib.h: In function גint main()ג:
  /usr/include/stdlib.h:738: error: too few arguments to function גint system(conג
  exm2.cc:7: error: at this point in file
  /usr/include/stdlib.h:738: error: too few arguments to function גint system(conג
  exm2.cc:8: error: at this point in file


推荐答案

因此,这些语句错误 / strong>:

So these statements are wrong:

system();
system();

如果你不想做任何事情,只要不要在里面放什么。

If you are not going to make anything, just don't put anything in there.

这篇关于从C ++程序调用linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆