|
||
|
|
#2 (permalink) |
|
Forum Expert
|
Don't know if it's the best way ( I'm learning C++ too ) but I would rather use cin.get() instead of declaring a slave variable.
Code:
cin.get();
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell! |
|
|
|
|
|
#4 (permalink) |
|
Master of the Internet
|
I found out what it is, the compiler I use runs it in a shell that closes when it is through. When i launch it from a command prompt it stops.
grrr. It still isn't what I want. When I launch the exe it opens it and closes it as soon as the results are displayed. This is with cin.get(); Last edited by DontdroptheSOAD; 12-30-2005 at 05:27 PM. |
|
|
|
|
|
#5 (permalink) |
|
Forum Expert
|
One of the best C++-standard way to do this is to use the istream::ignore() method with cin, ala
Code:
#include <iostream> #include <limits> ... std::cin.ignore(std::numeric_limits<std::streamsize>::max(), 'z'); Last edited by Sep102; 12-30-2005 at 06:01 PM. |
|
|
|
|
|
#6 (permalink) | |
|
Master of the Internet
|
Quote:
|
|
|
|
|
|
|
#9 (permalink) |
|
Forum Newbie
Join Date: Jul 2004
Posts: 59
|
Something I don't really like with the new VC++ .NET. The old VC6 used keep the console open. What I do is add a breakpoint just before the main() function ends and then run it in debug.
If someone has a solution to make it work like the old VC6 I'd be interested in knowing too ![]() |
|
|
|
|
|
#10 (permalink) |
|
Forum Expert
|
I don't exactly know the answer to that, however on both machines that I've installed the entirety of VS.NET 2003 on (one heavily configured and the other fully-default installed and unconfigured) both prompt me before quitting the application, thereby alleviating the need for me to do any of this, as do all of the other machines running it at my school.
Last edited by Sep102; 12-31-2005 at 03:46 AM. |
|
|
|
|
|
#13 (permalink) |
|
Garm Brood Cerebrate
|
You can also use
Code:
system("PAUSE");
__________________
Named after the fierce hellhound of Norse myth, the Garm strikes with alarming speed and ferocity. The minions of this Brood excel at hit and run raids that weaken their enemy's defensive formations. Zasz, the cunning Cerebrate of this Brood, delights in preemptive attacks, relying chiefly upon surprise to throw enemy forces into total chaos. |
|
|
|
|
|
#14 (permalink) | |
|
Forum Expert
|
Quote:
The way I presented is one of the few completely portable (as in, as long as the compiler supports the ISO C++ standard well enough) ways enacting a pause in the program. |
|
|
|
|
|
|
#16 (permalink) |
|
Master of the Internet
|
I do like the pause method, it is nice however i would like programs I write to be available in all supporting os's also I was wondering if I can use the method you mentioned Sep to work with the enter key. Because pressing a key and then hitting enter seems redundent. Like when a program says press anykey to exit it is just one thing to do rather than the "is that your final answer" approach by typing the key and then pressing enter.
|
|
|
|
|
|
#17 (permalink) |
|
Forum Expert
|
You can, to a point. When the enter key is pressed in a console, any characters are first read by an input device (or extracted and discarded with ignore) then a newline character is generated at the end ('\n') so ignoring up until a newline character will do what you want.
However, one caveat to this is if any other newline characters are still in the input buffer (via an earlier input or something of the sort) then the one ignore() will find that newline and end the statement without waiting like you wanted. This is not normal program flow however, as long as the user of the program enters only what they are supposed to, one could very well write a program with input where this would not happen. Thus for safety in a program with user-supplied inputs, use two ignore() statements at the end with a newline delimiter, with no user-supplied input, one ignore(). Last edited by Sep102; 01-03-2006 at 11:22 PM. |
|
|
|
|
|
#18 (permalink) |
|
Forum Novice
Join Date: Oct 2005
Posts: 142
|
in MSVC 2005:
1. CTRL+F5 to compile in debug, returns a "Press any key to continue..." prompt. 2. system("PAUSE"); returns a "Press any key to continue..." prompt 3. cin.get(); waits for any key input 4. Make a batch file and add a system("PAUSE");, returns a "Press any key to continue..." prompt |
|
|
|
|
|
#19 (permalink) |
|
Forum Expert
|
Code:
#include "conio.h"
char c = '\n';
while ( c = getch() && c != 'yourchar' )
{
}
__________________
Procrastinators unite!
Tomorrow. Saying that Java is nice because it works on all OS's is like saying that anal sex is nice because it works on all genders. ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|