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


at the end of your program write this command




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.

Thanks for the help everyone, I will give it a try this afternoon.

Thanks again


works a treat, thanks very much for everyones help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.