[英]I've created a new console in win32 window-only app, console is created but nothing gets print on it
此代碼是在gcc下使用-mwindows
編譯的,沒有winapi錯誤消息。
#include <windows.h>
#include <stdio.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int nCmdShow) {
AllocConsole();
printf("%s\n", "sample text");
return 0;
}
結果是控制台為黑色,沒有文本,沒有錯誤消息。
采用:
freopen("CONOUT$", "wb", stdout);
創建控制台后重新打開stdout
。 如果您也打算將其用於輸入,那么您需要:
freopen("CONIN$", "rb", stdin);
並且stderr可能也需要打開:
freopen("CONOUT$", "wb", stderr);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.