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?
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.
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.
You can use cin. get(); or cin. ignore(); just before your return statement to avoid the console window from closing.
Ctrl + F5 for quick test. The key combination keeps the console open until you close it.
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.
In c++ you want to use : OutputDebugString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With