Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: Otto on September 23, 2010, 12:41:48 am

Title: How to see output in a wxWidgets project?
Post by: Otto on September 23, 2010, 12:41:48 am
Hi,

I would like to know how do I check what was printed with a std::cout in a GUI (wx) during development.
I can't find any output window/view.

I only see output if I run the app outside C::B via CLI.


Thanks.
Title: Re: How to see output in a wxWidgets project?
Post by: oBFusCATed on September 23, 2010, 09:44:45 am
Set the type of your project to console and it will show you the output :)
Title: Re: How to see output in a wxWidgets project?
Post by: Otto on September 25, 2010, 02:31:46 am
That didn't work. The output window appears, but nothing is printed.
Title: Re: How to see output in a wxWidgets project?
Post by: Jenna on September 25, 2010, 09:43:45 am
That didn't work. The output window appears, but nothing is printed.
I just tested it (on linux) and it works fine.
Title: Re: How to see output in a wxWidgets project?
Post by: oBFusCATed on September 25, 2010, 10:58:04 am
Hm, if you're on windows you should read here: http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx

You need AttachConsole + a way to redirect stdout/stdin to the console... let google be your friend...
Title: Re: How to see output in a wxWidgets project?
Post by: Jenna on September 25, 2010, 11:58:57 am
Hm, if you're on windows you should read here: http://msdn.microsoft.com/en-us/library/ms682073%28VS.85%29.aspx

You need AttachConsole + a way to redirect stdout/stdin to the console... let google be your friend...
Tested on Vista and it works out of the box.
Title: Re: How to see output in a wxWidgets project?
Post by: Otto on September 25, 2010, 05:16:11 pm
I'm using Linux (Debian) and C::B 10.05.

I tested again and noticed it is only printed after I quit the program. I wasn't seeing because the output window is closed at that moment too. Have to keep "Pause when execution ends" checked.

Can't it be printed as soon as std::cout is called?
Title: Re: How to see output in a wxWidgets project?
Post by: Jenna on September 25, 2010, 05:39:53 pm
Tested again on linux (stepped through the code with debugger) and the output appears immediately after stepping over cout.
Title: Re: How to see output in a wxWidgets project?
Post by: Otto on September 25, 2010, 06:02:10 pm
That's nice, but it doesn't work for me. Is there anything I can do?

Ps: you're testing in a GUI (configured later to console) app, right? The cout is called when I do a GUI action (Menu help > about).
Title: Re: How to see output in a wxWidgets project?
Post by: stahta01 on September 25, 2010, 06:15:12 pm
Tested it and it works on Windows 6.1 AKA 7

Note: Flush was necessary to see output

Code
std::cout << "Test Message" << std::flush;

Remember to change project properties for target to "Console Application" and checkmark "Pause when Execution Ends"

Tim S
Title: Re: How to see output in a wxWidgets project?
Post by: Otto on September 25, 2010, 06:46:39 pm
Note: Flush was necessary to see output

Code
std::cout << "Test Message" << std::flush;
That was it! Thanks.

Sorry everyone, I'm new to C++.
Title: Re: How to see output in a wxWidgets project?
Post by: Jenna on September 27, 2010, 05:55:27 pm
I used std::endl as last argument and that also seems to flush.
Title: Re: How to see output in a wxWidgets project?
Post by: Otto on September 27, 2010, 11:55:52 pm
I confirm endl is enough.