How to see console results without window instantly closing.
15 replies, posted
[media]http://www.youtube.com/watch?v=zSjWeP-F5yw[/media]
I'm back with programing, but this time i'd like to see results just for a little bit. (like 3 sec delay before closing window down.)
You can add either "std::cin.get()" or "std::getchar()" to the end of your main(), so all you will need to do is press enter.
Your IDE (if you're using one) should have a setting for keeping the console window open.
If not, then you will have to do something like what Bumrang said.
In VS it should stay open by default if you run it without debugger.
[editline]edit[/editline]
In light of the ratings it's probably just in the C# configuration, or when using C#.
or include conio.h and use getch()
If you're going to use std::cin.get() or std::getchar() make sure the input buffer has been cleared before hand using std::cin.ignore();
system("pause");
note: don't use system commands as actual parts of the code. Just for debugging and testing and the like
[QUOTE=proboardslol;45478313]system("pause");
note: don't use system commands as actual parts of the code. Just for debugging and testing and the like[/QUOTE]
Lets take the time here to analyze with this reply has gotten 2 disagree and 2 agrees.
Why disagree: It's not crossplatform, only works on windows. Thusly the more savy programmers don't want you to use it.
Why agree: It fixes your immediate problem - doesn't need you to learn/mess with buffers to appropriately use it.
I personally agree, if it's JUST for debugging purposes, use system("pause");
system() calls can trigger antiviruses, it's safer not to use it.
[QUOTE=Corewarp3;45495186]Lets take the time here to analyze with this reply has gotten 2 disagree and 2 agrees.
[B]Why disagree: It's not crossplatform, only works on windows. Thusly the more savy programmers don't want you to use it. [/B]
Why agree: It fixes your immediate problem - doesn't need you to learn/mess with buffers to appropriately use it.
I personally agree, if it's JUST for debugging purposes, use system("pause");[/QUOTE]
You also forgot to add it's surprisingly resource heavy to do.
I don't see why anyone would use system("pause"); when he is pretty much going to be always using iostream. std::cin.get(); is the best option.
[QUOTE=reevezy67;45496104]system() calls can trigger antiviruses, it's safer not to use it.[/QUOTE]
hahaha I never knew that
[editline]25th July 2014[/editline]
[QUOTE=Proclivitas;45497145]I don't see why anyone would use system("pause"); when he is pretty much going to be always using iostream. std::cin.get(); is the best option.[/QUOTE]
cause its easy to remember and he's obviously a beginner so it doesnt really matter.
[QUOTE=proboardslol;45497434]
cause its easy to remember and he's obviously a beginner so it doesnt really matter.[/QUOTE]
One might argue it's better to learn the proper and better way from the start.
[QUOTE=Lord Fear;45505324]One might argue it's better to learn the proper and better way from the start.[/QUOTE]
Totally agree, counter-productive to teach someone something they are not going to want to use in the future.
[QUOTE=Proclivitas;45508414][QUOTE=Lord Fear;45505324]One might argue it's better to learn the proper and better way from the start.[/QUOTE]Totally agree, counter-productive to teach someone something they are not going to want to use in the future.[/QUOTE]This might be qn unpopular opinion, but dogmatism in programming is not as good as it sounds. The first thing any C programmer learns is what goto is and why never to use it (along with system commands), but this is only from the perspective of being someone else who has to deal with the code others have written and not from a purely acientific perspective. The GOTO statement CAN be used effectively and was used so for literally decades until better programming practices made it effectively obsolete. However, goto is a VERY rudimentary aspect of unstructured programming and a machine would simply not function without goto statements. Same thing as the system function, its better to teach the good programming practices that led to the obsoletion of goto and system(), rather than to simply dogmatically say not to use them because they're "annoying". In the process, one will learn about structured programming and good practices.Furthermore, if you need to write a platform-specific program, system is exactly what you need. Commercial software obviously ought not use it, but not all software is meant to be uaed by everybody, but simply is needed to solve a problem that exists here an now.
"They're annoying" is just a very simplified version of the reason why you generally don't use gotos in anything that supports something better. It's just short for "it's less readable than specific loops and conditionals to replace them in user code".
Sorry, you need to Log In to post a reply to this thread.