Call linux command from C ++ program

I am writing the following simple C ++ program to learn how to call a Linux command from a C ++ program (using a system command)

Please advice, why do I have errors in the C ++ compiler? what happened to my program?

more 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 
+1
source share
4 answers

You cannot use system() without the char* parameter.

Thus, these statements are incorrect :

 system(); system(); 

If you are not going to do anything, just do not put anything there.

+9
source

system () takes one argument, which you could call it an empty string:

 #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; } 

But you can just leave these lines :-)

+7
source

function system() requires a parameter. Try deleting the 7th and 8th row.

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

system accepts const char* . You call it 5 times without transmitting anything twice.

+2
source

Source: https://habr.com/ru/post/1339858/