When I build a simple console app with clang, it works fine:
void main() { puts("HELLO"); }
But when I create a Windows app with WinMain
, I can't see stdout.
There must be a flag that fixes it, like MinGW's -mconsole
When I build a simple console app with clang, it works fine:
void main() { puts("HELLO"); }
But when I create a Windows app with WinMain
, I can't see stdout.
There must be a flag that fixes it, like MinGW's -mconsole
A quick stdout-enabler for otherwise GUI apps:
if (AllocConsole())
{
FILE* fi = 0;
freopen_s(&fi, "CONOUT$", "w", stdout);
}
and then std::cout
and printf
work.
WinMain
is a custom microsoft entry function for a windows graphical application (with windows and menus etc). It doesn't have a console by default.
If you want a console program you should just use the standard main
function.
If you want a graphical application (WinMain
) that also has a console, then that's a little bit of work. Check How do I get console output in C++ with a Windows program? on how to achieve that.