How to write a program in C++ such that it will delete itself after execution ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to write a program in C++ such that it will delete itself after execution ?

3rd Jun 2017, 2:27 PM
Jerry Huang
Jerry Huang - avatar
3 Answers
+ 1
It doesn't work for Windows.
3rd Jun 2017, 2:41 PM
Jerry Huang
Jerry Huang - avatar
+ 1
batch file?
4th Jun 2017, 7:39 AM
Jerry Huang
Jerry Huang - avatar
0
You cannot really delete a file from itself, it's just nonsense. However the only way I think it would be possible is to call a Bash file (or similar OS language file) and delay it so that your program finishes and the Bash deletes your .exe.
3rd Jun 2017, 6:16 PM
Norbivar
Norbivar - avatar