|
-
Jul 27th, 2001, 05:50 PM
#1
Thread Starter
PowerPoster
Problem with VC++ console app
Just a little question that how do I keep the VC++ from terminating my console app about 1 sec after I run it. I tried teh following codes to get not close my app until a key is pressed but that does not work in VC++
system("PAUSE")
OR
gethcar();
If there any other way to not close the app until a key is pressed?
-
Jul 27th, 2001, 06:05 PM
#2
Frenzied Member
Just do something like
int dummy;
cin>>dummy;
return 0;
thats what I do
-
Jul 27th, 2001, 06:40 PM
#3
Thread Starter
PowerPoster
But there should be a better way to do it because when I use that code, I cannot exit from my app with just the <enter> key. I need to type some letter or number in order to exit.
getchar(); was working for me on Dev-C++ but I dont why it is not working on VC++
-
Jul 28th, 2001, 06:44 AM
#4
Addicted Member
With this code the programme will only exit after the Esc key has been pressed:
Code:
#include <iostream.h>
#include <conio.h>
void main()
{
char keyPress;
cout << "Hello World";
do
{
keyPress = getch();
}while(keyPress != 27);
}
As a char is really just like an int you can refer to it as a number and in so doing you're referring to an ASCII value.
Last edited by hypnos; Jul 28th, 2001 at 07:06 AM.
-
Jul 28th, 2001, 06:55 AM
#5
Addicted Member
BTW, if you wanted the programme to exit after you pressed the enter key then you would use the number 13 and not 27. 13 is the <enter> key's ASCII code. If you would like to know the ASCII code for a particular key then you can download a programme I made around a year ago: http://geocities.com/hypnos_ric/vb/t...Translator.zip (It's nothing special but it does the job )
Also, the reason I used getch is because it doesn't echo to the screen.
Last edited by hypnos; Jul 28th, 2001 at 07:01 AM.
-
Jul 28th, 2001, 12:30 PM
#6
Thread Starter
PowerPoster
ESC key is also good.
I just did not want to use cin>> thingy
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|