6

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?

futlib
  • 8,258
  • 13
  • 40
  • 55

6 Answers6

7

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

digit plumber
  • 1,140
  • 2
  • 14
  • 27
  • This. You don't need to write any artificial code to do this. – Tim May 26 '11 at 18:12
  • Brilliant, works! Just curious: is there no menu option for this? – futlib May 30 '11 at 10:23
  • It used to be under the Debug drop menu in MSVS 2008 Express but removed in 2010 Express. The full version of MSVS 2010 still has it under Debug: Start Without Debugging, Ctrl + F5 – digit plumber May 31 '11 at 18:37
2

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.

futlib
  • 8,258
  • 13
  • 40
  • 55
  • Very useful if Ctrl-F5 doesn't work (e.g. you need /SUBSYSTEM:CONSOLE for the Ctrl-F5 to work and using NMAKE/SCons I haven't figured out how to do that yet) – danio Jan 24 '13 at 13:47
  • @danio See my answer [here](http://stackoverflow.com/questions/454681/how-to-keep-the-console-window-open-in-visual-c/23288778#23288778) for how to fix the bug which prevents it working in makefile projects. – JBentley Apr 27 '14 at 22:24
  • @JBentley thanks, SCons generates the vcxproj so patching it to be to add that tag would be a solution – danio May 07 '14 at 10:21
1

In c++ you want to use : OutputDebugString

Blazes
  • 4,721
  • 2
  • 22
  • 29
0

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.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
0

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

Paul
  • 35,689
  • 11
  • 93
  • 122
  • I don't think I can (or want to) fiddle with Boost.Test until it uses that instead of stdout. – futlib May 26 '11 at 15:00
0

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.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85