当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - 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?

网友答案:

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.

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: