Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ on Windows - the console window just flashes and disappears. What's going on? [duplicate]

Possible Duplicate:
Visual Studio Console App - Prevent window from closing.

I'm starting to learn C++ on Windows and I'm trying a few different development environments: 1. Netbeans with Cygwin compiler 2. MS Visual Studio 2010

For either of them, when I write a very simple Hello World program, I build it and it's fine. But when I try to run the program, the command prompt window pops up really quick and then disappears right away.

This happens whether it's in Debug or Release config. Please help with this - I can't see my program output! :(

Thanks.

EDIT1: Thanks for the replies. This is my code:

#include <iostream>

int main()
{
    std::cout << "This is a test." << std::endl;
    return 0;
}

I tried Ctrl+F5 for "Start without Debugging" and that doesn't work. It still flashes the black console screen then disappears right away.

I also tried adding in std::cin.get(); and this works with Ctrl+F5, but isn't that a really... inelegant workaround solution? I'd rather have my program in the final form.

The breakpoint works, but then I have to run with debugging and the console window flashes and disappears, but then it stays in the background. Any way to get the console to stay in the foreground so I can see program output right away? Seems like that's how it should work.

Any more ideas? Why wouldn't Ctrl+F5 work?

like image 493
John Smith Avatar asked Nov 12 '10 11:11

John Smith


3 Answers

After you are done with your program, press Ctrl + F5 ( Run without debugging). This will prompt before closing the window and this is what you want.

like image 128
user225312 Avatar answered Oct 19 '22 23:10

user225312


Write cin.get() at the end of the program.

like image 26
Simone Avatar answered Oct 19 '22 23:10

Simone


use Ctrl+F5 to run your program or set a break point in the last line or write cin>> to any vraiable at the end....etc

like image 27
Mohamad Alhamoud Avatar answered Oct 19 '22 23:10

Mohamad Alhamoud