【问题标题】:C++ AttachConsole include errorC++ AttachConsole 包含错误
【发布时间】:2013-10-22 01:49:39
【问题描述】:

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

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

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

#define _WIN32_WINNT 0x0502

int main() {
    AttachConsole(8336);
}

【问题讨论】:

    标签: c++ windows user-interface console


    【解决方案1】:

    当然,您需要将_WIN32_WINNT 定义为>= 0x0501,但您需要在 包括Windows 标头之前这样做,否则它将不起作用。

    改为这样做:

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

    【讨论】:

    • oh f*ck :D 我已经尝试了好几个小时了.. :D
    猜你喜欢
    • 2012-07-08
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    相关资源
    最近更新 更多