我编写了以下简单的 C++ 程序,以便学习如何从 C++ 程序调用 Linux 命令(通过使用系统命令)
请告诉我为什么 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
你不能使用system()
没有char*
范围。
所以这些陈述是wrong:
system();
system();
如果你不打算做任何东西,就不要把任何东西放在那里。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)