Hi All,

I am currently learning C++ and i have started to write some small programs that explain operators, integers and values, my question is this.

How do I make my programs stay on screen, at the moment I run my program it displays the message on screen for about a second then disapeers. Is there a line of code that keeps my program running until I hit the return button or the escape button???

I would like to enjoy the fruits of my labour for more than a second :)

Thanks very much



This may or may not work. getch() is not a standard function and not all compilers implement it as an extension. If the only goal is to keep the window open, any blocking read will do:

#include <iostream>

int main()
    std::cout << "Hello world!\n";

    // blocking read to keep the window open
    std::cout << "Press [Enter] to continue";

This program is portable because cin.get() is a standard method with well defined behavior.

This question has already been answered. Start a new discussion instead.