Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
I want reset my program. for example if I press key R my program start from begin
how can I do that ?
Posted

Hi,

For a console application:
At the top of your code file, add this:
C++
#include <conio.h>

In your main method:
C++
bool stop = false;
while (!stop)
{
      system("cls"); // clear console
      // run your program
      int pressedChar = getch();
      stop = pressedChar != 114; // 114 = 'R'
}
return 0;

For a Windows application:
Have a look here:
http://www.cplusplus.com/forum/windows/42674/[^]
How To Create a Self-Restartable Application[^]

Hope this helps.
 
Share this answer
 
v3
Comments
Abhishek Pant 23-Dec-12 8:45am    
+5
Thomas Daniels 23-Dec-12 8:46am    
Thank you!
mohammadali1375 23-Dec-12 9:20am    
thanks. but my program is'n a console program. its a 2d game with sdl and have alot of class and vars. i want after the game end , my program re start for play again.
Thomas Daniels 23-Dec-12 9:21am    
Thanks for your reply!
I'll try to find how to restart a Windows application.
mohammadali1375 23-Dec-12 9:55am    
Thanks for your help
You need to add a method to your main class that purges all views and documents and resets all control variables to their initial state. However, only you know what those things are.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900