Jump to content
  • Advertisement
Sign in to follow this  
emforce

keeping program running so can see results

This topic is 3412 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys, how do i keep my programs open soo i can see results? for instance i made a calculator(very simple) and would like to see the answer to the sums i put in but the console screen closes almost instantly after inputting data, please help me :D

Share this post


Link to post
Share on other sites
Advertisement
I am assuming C++?

Try using std::cin.get()

#include <iostream>
...
int main(...){


...


std::cout << "Press enter to continue" << std::endl;
std::cin.get()

}




Share this post


Link to post
Share on other sites
Your development environment should have an option for keeping the window around until it's closed (for instance, Visual C++ does so by default in certain build configurations).

If it doesn't, a simple workaround is to add a debugger breakpoint on the last statement in your program—this doesn't require you to change the program, and has no effect on the program when it's run outside the IDE.

Share this post


Link to post
Share on other sites
If you are using Visual Studio, you have two additional options.

You can press CTRL+F5 to build and run your program. When it is done, the window will stay open.

You can also place a breakpoint at the return statement to your main function and then run your code with the debugger. When the program gets to the end, the program will stop and wait for you to continue at which point you can go back to the output window to make sure everything is okay.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Your development environment should have an option for keeping the window around until it's closed (for instance, Visual C++ does so by default in certain build configurations).

If it doesn't, a simple workaround is to add a debugger breakpoint on the last statement in your program—this doesn't require you to change the program, and has no effect on the program when it's run outside the IDE.


Quote:
Original post by stonemetal
Run your program from the terminal.


Quote:
Original post by mmakrzem
If you are using Visual Studio, you have two additional options.

You can press CTRL+F5 to build and run your program. When it is done, the window will stay open.

You can also place a breakpoint at the return statement to your main function and then run your code with the debugger. When the program gets to the end, the program will stop and wait for you to continue at which point you can go back to the output window to make sure everything is okay.


Do any of these.

Alternatively, make a batch file which runs your program, and then runs the 'pause' program.

Quote:
Original post by Yacoby
I am assuming C++?

Try using std::cin.get()
*** Source Snippet Removed ***


Please don't do this (nor system("PAUSE"), nor anything else intended to artificially pause your program itself at the end).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!