Can't see Windows program's stdout in console (compiled with Clang on Windows)

人盡茶涼 提交于 2020-01-23 17:35:02

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/55458264/cant-see-windows-programs-stdout-in-console-compiled-with-clang-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!