Results 1 to 6 of 6

Thread: Problem with VC++ console app

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    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?
    Baaaaaaaaah

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Just do something like

    int dummy;
    cin>>dummy;
    return 0;

    thats what I do

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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++
    Baaaaaaaaah

  4. #4
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    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.

  5. #5
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    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.

  6. #6

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    ESC key is also good.

    I just did not want to use cin>> thingy

    Thanks!
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width