gpt4 book ai didi

c++ - 如何从 C++ 程序中调用 Linux 命令?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:04:59 34 4
gpt4 key购买 nike

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

请指教为什么我有 C++ 编译器的错误?我的程序有什么问题?

更多exm2.cc

#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

最佳答案

您不能在没有char* 参数的情况下使用system()

所以这些陈述是错误的:

system();
system();

如果你不打算做任何东西,就不要在里面放任何东西。

关于c++ - 如何从 C++ 程序中调用 Linux 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5007268/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com