Skip to main content
gamedev.net
🔒 Locked

Hello c++

Started by callmenick 2 replies 200+ views
Original Post
callmenick
callmenick
i tried running the hello world program on my compiler. it flashes so quick i dont get to see it. im using bloodshed dev-c++ as my compiler. i cant find any options to slow down the program or make it stay until i tell it to exit. how do i get to see my great work of art??
Miserable
Miserable
This should be in a FAQ somewhere. The reason this happens is because you're calling a console program while not in a console, so a console window is created, but it's destroyed as soon as the program is done. The easiest way of fixing this is simply making sure that the program doesn't terminate until you've had time to read the text, and the easiest way to do this is to wait for user input before terminating.

Quick and dirty solution: Make sure to #include <conio.h>, and at the very end of your program, call getch(). This reads a character from the keyboard and, therefore, will wait until a key is pressed before the program can continue.


        
#include <conio.h>

#include <iostream>

int main(void)
{
std::cout << "Hello world!" << std::endl;
getch();
}


[edited by - Miserable on January 3, 2003 2:01:58 AM]
dede
dede
Another trick that is widly used is typing this at the end of your code


#include <iostream>

int main(void)

{
std::cout << "Hello world!" << std::endl;
system("PAUSE");
}


On a side note...
>how many C++ programmers does it take to change a lightbulb?

50, 1 to do it, and 49 to discuss how they could have done it better, and faster...


Monder
Monder
to use system( ); you have to #include <stdlib.h>, if you''re wondering why the above program will not compile

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.