Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Visual Studio: How to keep the console open without manually reading input?

I'm writing some C++ with Microsoft Visual Studio 2010 Express, and I'm wondering if there is a way to display command output somewhere in the IDE instead of an external console window, or at least keep that window open.

Reading something from STDIN would work for a console application, but this is a unit test case and I don't want to modify the generated main function. Is there another way?

like image 795
futlib Avatar asked May 26 '11 10:05

futlib


People also ask

How do I keep the console open in Visual Studio?

To keep the console window open in Visual Studio without using the Console. ReadLine() method, you should run the application without debug mode by pressing Ctrl+F5 or by clicking on the menu Debug > Start without Debugging option. This way the application remains active below until the user presses a key.

How do I keep the console open in C#?

The first solution is to run the application without debugging by using Ctrl+F5 instead of just F5. The console window will remain open when the program has finished. The disadvantage of this is that you lose Visual Studio's debug information.

What is the line of code to keep the console window open?

You can use cin. get(); or cin. ignore(); just before your return statement to avoid the console window from closing.


3 Answers

Ctrl + F5 for quick test. The key combination keeps the console open until you close it.

like image 50
digit plumber Avatar answered Sep 22 '22 01:09

digit plumber


I've found a solution that is not really elegant, but at least it works. I'm using a fixture in my unit testing framework (Boost.Test) which does system("pause") in the tear down method:

struct Global_fixture {
    Global_fixture() {}

    ~Global_fixture()
    {
        system("pause");
    }
};
BOOST_GLOBAL_FIXTURE(Global_fixture)

I hope you guys can find a better way.

like image 43
futlib Avatar answered Sep 22 '22 01:09

futlib


In c++ you want to use : OutputDebugString

like image 43
Blazes Avatar answered Sep 19 '22 01:09

Blazes