C++附加控制台包含错误

C++ AttachConsole include error

本文关键字:包含 错误 控制台 C++      更新时间:2023-10-16

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

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

#include <iostream>
#include <stdio.h>
#include <windows.h>
#define _WIN32_WINNT 0x0502
int main() {
    AttachConsole(8336);
}

当然,您需要定义_WIN32_WINNT>= 0x0501,但是您需要在包含Windows标头之前这样做,否则它将没有任何影响。

请改为执行以下操作:

#include <iostream>
#include <stdio.h>
#define _WIN32_WINNT 0x0502
#include <windows.h>
int main() {
    AttachConsole(8336);
}