FILE* pCout; AllocConsole(); freopen_s(&pCout, "CONOUT$", "w", stdout); Then if you close the console you shut down the entire application. To prevent that happening accidentally you can add : EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND | ...