opsb
opsb

Reputation: 30211

Print to console in visual studio 2005

I want to print debug statements to the Output window(or anywhere else I can see it) in visual studio 2005. The advice I've seen has said to use

OutputDebugString("message");

and to ensure that I have

Options -> Debugging -> Redirect all Output Window text to the Immediate Window checked

while the code builds ok I don't see any output, what's the trick?

Upvotes: 0

Views: 2391

Answers (4)

Baiyan Huang
Baiyan Huang

Reputation: 6771

If your code does hit that line, then it maybe:

RMB in your VS's output window:

alt text

Check if you have "Program Output" unchecked, if yes, check it!!!

Although this control exist in output windows's context menu, it does impact the output in immediate window as you redirect it.

Upvotes: 0

Clifford
Clifford

Reputation: 93476

Alt-2 or View->Output to open the Output Window. By default it should already be open, it is generally in the tabbed window at the bottom of the IDE (but that will depend on your custom layout), and is labelled "Output".

The output is not directed to the console, you need to output to stdout for that and create a console window for it.

Upvotes: 0

kichik
kichik

Reputation: 34704

If you're using OutputDebugString, you can also use SysInternal's DebugView to see the output. Until you resolve your Visual Studio debugging issues, DebugView should do the trick.

Upvotes: 2

Liviu Mandras
Liviu Mandras

Reputation: 6617

You must run in Debug mode first.

Then use the following code (from MSDN):

class Test{
static void Main()
{
   Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
   Debug.AutoFlush = true;
   Debug.Indent();
   Debug.WriteLine("Entering Main");
   Console.WriteLine("Hello World.");
   Debug.WriteLine("Exiting Main"); 
   Debug.Unindent();
}}

You will see everything in the Output window. You may have to go to the View->Output menu to make this window visible in the IDE.

Upvotes: 0

Related Questions