1

如何包含 AttachConsole?我总是收到“未在此范围内声明”错误。

我发现这个“要编译使用此函数的应用程序,请将 _WIN32_WINNT 定义为 0x0501 或更高版本。有关详细信息,请参阅使用 Windows 标头。” 在 Microsoft MSDN网站上,但无法正常工作。

#include <iostream>
#include <stdio.h>
#include <windows.h>

#define _WIN32_WINNT 0x0502

int main() {
    AttachConsole(8336);
}
4

1 回答 1

3

当然你需要定义_WIN32_WINNT为 >= 0x0501,但是你需要在包含 Windows 头文件之前这样做,否则它不会有任何效果。

改为这样做:

#include <iostream>
#include <stdio.h>

#define _WIN32_WINNT 0x0502
#include <windows.h>

int main() {
    AttachConsole(8336);
}
于 2013-10-14T13:22:59.793 回答