Follow us on Twitter!
Society leans ever heavily on computers, if you have the power to take out computers you can take out society. - cubeman372
Wednesday, April 23, 2014
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Members Online
Total Online: 14
Guests Online: 13
Members Online: 1

Registered Members: 82876
Newest Member: bhl1986
Latest Articles

C++ system( ) tutorial

Arrow Image explains how to use the system ( ) in C++. short in length, but hopefully helpful

This is my first tutorial on C++, and I hope that this helps out some people. I will be talking about the system( ) command in C++


In C++, the system ( ) allows your to add system commands in your C++ source. When I say “system commands”, and I am talking about commands such as MS-DOS commands (ping, netsh, ipconfig). The system ( ) also works with linux commands, but you must be on a computer running linux to use them (I will primarily be talking about Windows system commands).


Below is the basic syntax of the C++ system ( ):

#include <iostream>
using namespace std;

int main ()

Keep in mind that your system command needs to be within the quotations. There really isn’t that much to system commands (other than putting in system commands in the system ( )), but I will give an example of how you could incorporate the system ( ) in your C++ code:

#include <iostream>
#include <fstream>
using namespace std;

int main ()
ofstream out (\"file1.txt\");

out << \"Hello World!\";

system(\"copy file1.txt file1.txt\");

return 0;

the above code is an example of how you could make a file in C++, and then copy that file using the system command.


system_meltdownon September 01 2006 - 17:43:51
Cool article, the best thing with system is this: system("shutdown -c \"Owned.\" -s -t 01"Wink; Grin
remotec2on September 02 2006 - 00:40:07
thanks Wink i think that i will eventually add more if i need to, but for now i think that it is good enough Wink
T-Metal-Risenon September 03 2006 - 07:38:25
This article was pretty poorly written and didn't provide a lot of information on the actual beneficial uses of using system(), which are close to none I might add since it isn't portable.
remotec2on September 03 2006 - 17:27:04
there isnt a whole lot that you could write about with the system () command, and it mostly depends on what the people who are using system() want to do. I just gave one example, but there could more depending on what the person wants to do.
wolfmankurdon September 09 2006 - 22:30:03
... this article is 40 lines too long. system(cmd) was enough, hbh isn't a c++ manual you hsould have explained thats it's near useless unless you are using in for your own stuff
the_gr8_ruleson September 11 2006 - 13:44:16
i can't comment on the quality of this article. But i just wan't to express my thanks to the author b'coz i didnt' knew about this command before.
deathaliveon September 29 2006 - 18:43:24
remotec2: try to write your own copy program, and don't use system command for that ;-)
fluxcoderon July 13 2009 - 03:48:57
it explains the really really basics... but i always use: #include <stdlib.h> always thought that you needed that for system() still seems ok,
Tyler3791on December 18 2009 - 01:14:03
It's bad practice, you should just take the time to learn the WinAPI alternative. Another reason to use an OSes API as opposed to this is that system() has to be interpreted by the command interpreter which then calls the correct function. In other words, it causes a crap load of overhead.
Zkunxenon May 03 2010 - 02:29:03
couldn't you use a macro to make this command portable, eg: #ifdef WIN32 #define x strcat("del ", argv[1]) #endif #ifdef NIX #define x strcat("rm ", argv[1]) #endif ... system(#x); then compile for windows with -D WIN32 or *nix with -D NIX? not that I'm endorsing the system command, I've never used it for anything, except a fail attempt to use the clear command, and as it didn't work, I reworked the program to not need it... (and I definitely did not write an entire line of \n... <.< )
Post Comment


You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.