Visual C++ 报告传递给 的参数无效fclose
,该参数FILE*
由 freopen_s 返回:
#include <WinSock2.h>
#include <iostream>
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(nCmdShow);
#ifdef _DEBUG
AllocConsole();
#else
AttachConsole(ATTACH_PARENT_PROCESS);
#endif
FILE* pCout;
freopen_s(&pCout, "conout$", "w", stdout); //returns 0
fclose(pCout);
#ifdef _DEBUG
system("pause");
#endif
FreeConsole();
return 0;
}
我不应该尝试在程序结束时关闭 conout$ 吗?是否因为文件指针在所有控制台输出的进程之间共享而引发异常?