...

View Full Version : C++ (help)



Fashong
02-26-2005, 10:55 PM
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++

redoc
02-27-2005, 04:53 AM
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.

aman
02-27-2005, 05:48 AM
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.


int main()
{

getchar(); // wait here untill a user presses enter
return 0;
}

deadimp
02-28-2005, 01:52 AM
You can use GetAysncKeyState() if you want it more specific:
[code]#include <windows.h>

int main() {
...
while (GetAynscKeyState(VK_ESCAPE)==0) { }
return 0;
}

jkd
02-28-2005, 01:59 AM
I just threw a
cin; at the end of my main() function, I think...

Mhtml
02-28-2005, 07:41 PM
or there's even the system command:


int main(){
...
system("pause");
}


Include stdlib.h if I remember correctly.

aman
03-01-2005, 11:32 AM
I just threw a
cin; at the end of my main() function, I think...

The correct way to use cin to pause the program would be..


int main()
{
...
cin.ignore();

return 0;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum