locked
Console::Write output to the Output window like C# RRS feed

  • Question

  • Why doesn't VisualStudio C++ 2005 send the Console::Write output to the "Output" window?  This behavior exists in C#, but C++ acts differently. 

     

    In researching the issue, I found a reference the "Quick Console" window (was this something the beta version?).  But, the closest thing I could find in 2005 Standard is Tools->Options->Debugging->General->Redirect All Output Window text to the Immediate Window.  But, this doesn't seem to have much effect in C++ (didn't see a difference whether is was checked or not). 

     

    The second workaround/solution involved adding the include file and using AllocConsole

    Code Block

    Form1(void)

    {

      InitializeComponent();

      // Allocate a console window

      AllocConsole();

      Console::WriteLine("Test");

    }

     

    /// <summary>

    /// Clean up any resources being used.

    /// </summary>

    ~Form1()

    {

      if (components)

      {

        delete components;

      }

      // Free the console window

      FreeConsole();

    }

     

     

    And this gets the output, but outside of the IDE in a seperate Command Prompt window. 

     

    There was also reference to using Trace:: instead of Console::, but I just want a console dump like C# does.  Mostly so I can have Console::Writes and log4net (with Console Appender) output in a consistent place.

     

    Is this possible in C++?  Is there another setting I'm missing? 

     

    Thanks.

    Thursday, November 8, 2007 1:00 AM

Answers

  •  doobop wrote:

    The only time I use Console::Write is for quick and dirty debug info.  It's not intended to stick around and is not desired at all for a release build - just for my own debug sessions.  If I need something longer lasting, I'll just put in a log entry which gets written to a text file.  The console just lets me view things easily while debugging.

     

    You can use the Trace class for this purpose. All you need to do is replace Console::Write  with Trace::Write

     

     doobop wrote:

    I just find it odd that .NET, which touts itself for a common runtime between the different langues, has a different behavior between C# and C++. 

    In this context, .NET basically touts interoperability between components built with different languages. The IDE behavior will be be slightly different for different languages.

    Friday, November 9, 2007 5:56 AM

All replies

  • For diagnostics you can use Trace::Write, the result is displayed in the output window while running the app from the IDE.  Apart from that do not use console output in a Windows application, it has other means of communicating with the user.  A GUI application that writes to the console is said to suffer from an identity crisis, i.e. it's not sure if it's a GUI application or a console application.  Using this approach can lead to several problems, specially if others are using components you create. Please see this thread for a tale of an encounter with a schizophrenic dll

    Thursday, November 8, 2007 4:59 AM
  •  doobop wrote:

    Why doesn't VisualStudio C++ 2005 send the Console::Write output to the "Output" window?  This behavior exists in C#, but C++ acts differently.

    I have not used C# enough to understand what you are saying, but I would sure complain about C# if it did that to me. For one thing, the "Output" window exists only when the debugger is used, so a release build would have no output. It seems bizarre to me that C# works like that.

     

     doobop wrote:

    In researching the issue, I found a reference the "Quick Console" window (was this something the beta version?).  But, the closest thing I could find in 2005 Standard is Tools->Options->Debugging->General->Redirect All Output Window text to the Immediate Window.  But, this doesn't seem to have much effect in C++ (didn't see a difference whether is was checked or not).

    The "Immediate Window" is not the same as the "Output" window. You are probably confusing them.

    Thursday, November 8, 2007 7:16 AM
  •  Sahir Shah wrote:

    Please see this thread for a tale of an encounter with a schizophrenic dll

    Please understand that the requirements for that question are different; essentially this question is totally different. In this question, the requirement is to direct output to a console or a non-console wihout additional software. In that other thread, the requirement is to redirect output that the original program intends to go to the console.

    Thursday, November 8, 2007 7:31 AM
  • Thanks for the responses. 

     

    The only time I use Console::Write is for quick and dirty debug info.  It's not intended to stick around and is not desired at all for a release build - just for my own debug sessions.  If I need something longer lasting, I'll just put in a log entry which gets written to a text file.  The console just lets me view things easily while debugging.  I can have the AllocConsole, but that means I have code that actually could ship and display or surround it the ifdef's.  In addition, the output isn't conviently located in the IDE, I need to bring the window into the display. 

     

    I just find it odd that .NET, which touts itself for a common runtime between the different langues, has a different behavior between C# and C++. 

     

    Thanks again.

    Thursday, November 8, 2007 9:22 PM
  • Sometimes people spend a lot more time complaining than explaining. If you had provided in the original question the additional explanation you did in this last post, you would have gotten better answers.

    Thursday, November 8, 2007 9:49 PM
  •  doobop wrote:

    The only time I use Console::Write is for quick and dirty debug info.  It's not intended to stick around and is not desired at all for a release build - just for my own debug sessions.  If I need something longer lasting, I'll just put in a log entry which gets written to a text file.  The console just lets me view things easily while debugging.

     

    You can use the Trace class for this purpose. All you need to do is replace Console::Write  with Trace::Write

     

     doobop wrote:

    I just find it odd that .NET, which touts itself for a common runtime between the different langues, has a different behavior between C# and C++. 

    In this context, .NET basically touts interoperability between components built with different languages. The IDE behavior will be be slightly different for different languages.

    Friday, November 9, 2007 5:56 AM
  • I have a similar issue but I an not using .NET Framework but rather it is a Windows WIN32 application.

    I belive that the Trace class is in the .NET framework. How can I get console/debug output to the Output Window in Visual Studio.

    Thanks
    Liam
    Wednesday, November 21, 2007 3:53 PM