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

淺唱寂寞╮ 提交于 2019-12-01 17:14:18

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

I think Debug.Write (and related) should do what you're looking for. Writes to the VS output window.

If you're running unit tests, you're not debugging, right? So use "Run withut debugging" and the console window will stay open.

Alternatively, open a command prompt of your own and launch the exe by typing its name.

Roger Pearse

In VC++ use

Console::WriteLine(L"my error text");

Printf won't produce any output. Neither will OutputDebugString. The Console will write at the bottom of the test results output, so all you have to do is double-click on the test in the "Test Results" window.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!