質問

I need to run a program after my main program exits, is it possible to get the main program to run it on exit?

役に立ちましたか?

解決 3

The simplest way to run something after main ends in a C++ program, is to do it in the destructor of a static object.


If you're talking about after the program terminates, then that is wholly outside the realm of standard C++. You'd have to use OS-specific means for that. However, the simplest then (assuming you need the whole thing to happen automatically) is to invoke your program via a command or script that runs first your program, and then the second program.

他のヒント

You could make a script (or again better another program) which executes the your two programs in sequence.

You might find atexit useful (not sure what's your actual need). It will run the registered function just before your program ends. Note that in order for the code to run after your program ends, you must create a new process.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top