Executing a file or program

Hi
Is there a way I can lunch/execute a program or text file with my cpp code?
I know I will be hit by other guys in this Forum but if you are operating on Windows and you want an easy solution you could use system.

1
2
3
4
5
6
7
8
#include <stdlib.h>

int main()
{
    system("test.exe");

    return 0;
}
Last edited on
Nothing wrong with using system, just keep in mind in the future if you want to call other programs you may want to consider other methods because system can fail to call what you want to call depending on the environment variables (PATH) and some other factors (some malicious)

Consider using CreateProcess for executables
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

For binary files you can open them with fstream
http://www.cplusplus.com/reference/fstream/fstream/
Last edited on
system("test.exe");
worked just fine tnx
Topic archived. No new replies allowed.