Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2005, 10:55 PM   PM User | #1
Fashong
New Coder

 
Join Date: Jan 2005
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Fashong is an unknown quantity at this point
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++
Fashong is offline   Reply With Quote
Old 02-27-2005, 04:53 AM   PM User | #2
redoc
New Coder

 
Join Date: Jan 2005
Location: Iowa City
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
redoc is an unknown quantity at this point
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.
redoc is offline   Reply With Quote
Old 02-27-2005, 05:48 AM   PM User | #3
aman
Regular Coder

 
Join Date: Oct 2004
Posts: 230
Thanks: 0
Thanked 0 Times in 0 Posts
aman is an unknown quantity at this point
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;
}
aman is offline   Reply With Quote
Old 02-28-2005, 01:52 AM   PM User | #4
deadimp
New Coder

 
Join Date: Nov 2003
Location: I have no life
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
deadimp is an unknown quantity at this point
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.
deadimp is offline   Reply With Quote
Old 02-28-2005, 01:59 AM   PM User | #5
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
I just threw a
Code:
cin;
at the end of my main() function, I think...
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 02-28-2005, 07:41 PM   PM User | #6
Mhtml
Senior Coder

 
Mhtml's Avatar
 
Join Date: Jun 2002
Location: Sydney, Australia
Posts: 3,531
Thanks: 0
Thanked 1 Time in 1 Post
Mhtml is an unknown quantity at this point
or there's even the system command:
Code:
int main(){
   ...
   system("pause");
}
Include stdlib.h if I remember correctly.
__________________
Omnis mico antequam dominus Spookster!
Mhtml is offline   Reply With Quote
Old 03-01-2005, 11:32 AM   PM User | #7
aman
Regular Coder

 
Join Date: Oct 2004
Posts: 230
Thanks: 0
Thanked 0 Times in 0 Posts
aman is an unknown quantity at this point
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;
}
aman is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:39 PM.


Advertisement
Log in to turn off these ads.