A problem with -mwindows command

While going through some win32 api tutorials with CodeBlock I was required to add -mwindows into the linkers setting to get rid of the "Undefined reference to GetStockObject@4" error, however when I switch back to doing some console program I noticed that I cannot use cout.
For example:
1
2
3
4
5
6
7
#include <iostream>
using namespace std;
int main()
{
     cout << "HI";
     return 0;
}

This code did not produce any error but when I ran the program the console did not display "HI", but when I removed -mwindows command from the linkers option and compile the code again, "HI" was display on the console. Am I the only person experience this problem or is there something that I am missing? Thank you.
Add libgdi32.a to linker input, do not use -mwindows switch, altough I wonder why do you need GDI if you are wriring a console application.
Thank you modoran. I do not need GDI to write a console program but was curious as to why -windows would cause this problem when I added it into linkers setting.
I found a similar description online for no text output when using -mwindows (which was in the context of a GNAT program). According to the GNAT user manual, -mwindows does not create a console for the output to be displayed. See here:

There are two main subsystems under Windows. The CONSOLE subsystem (which is the default subsystem) will always create a console when launching the application. This is not something desirable when the application has a Windows GUI. To get rid of this console the application must be using the WINDOWS subsystem. To do so the -mwindows linker option must be specified.


http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gnat_ugn_unw/CONSOLE-and-WINDOWS-subsystems.html#CONSOLE-and-WINDOWS-subsystems
That explained so much, thank you Ogoyant.
Topic archived. No new replies allowed.