Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: C++ (help)

  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C++ (help)

    Im new at C++ and I wanted to know how to keep the console app up so when you compile and run it, it stays up instead of doing output and exiting. Also I wanted to know how to make a GUI program with C++

  • #2
    New Coder
    Join Date
    Jan 2005
    Location
    Iowa City
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I may be wrong, by I assume you are on windows? If so, if you open a command prompt (on winXP goto start>run and type cmd) then you can compile and execute programs with the window staying up.
    PS - this is what part of the alphabet would look like if Q and R were eliminated.

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Like redoc said, you can just run the program in a command prompt where the output will stay visible, or at the end of your main function add a line of code that will wait for user input before it closes.
    Code:
    int main()
    {
    
        getchar(); // wait here untill a user presses enter
        return 0;
    }

  • #4
    New Coder
    Join Date
    Nov 2003
    Location
    I have no life
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use GetAysncKeyState() if you want it more specific:
    [code]#include <windows.h>

    int main() {
    ...
    while (GetAynscKeyState(VK_ESCAPE)==0) { }
    return 0;
    }
    Come to my site, currently under construction.

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I just threw a
    Code:
    cin;
    at the end of my main() function, I think...

  • #6
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    or there's even the system command:
    Code:
    int main(){
       ...
       system("pause");
    }
    Include stdlib.h if I remember correctly.
    Omnis mico antequam dominus Spookster!

  • #7
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    I just threw a
    Code:
    cin;
    at the end of my main() function, I think...
    The correct way to use cin to pause the program would be..
    Code:
    int main()
    {
        ...
        cin.ignore();
    
        return 0;
    }


  •  

    Posting Permissions

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