简体   繁体   中英

C++ AttachConsole include error

How can I include AttachConsole? I always get "was not declared in this scope" error.

I found this "To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later. For more information, see Using the Windows Headers." on Microsoft MSDN website , but not working.

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

#define _WIN32_WINNT 0x0502

int main() {
    AttachConsole(8336);
}

Of course you need to define _WIN32_WINNT to be >= 0x0501, but you need to do so before including the Windows headers, else it will have no effect whatsoever.

Do this instead:

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

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

int main() {
    AttachConsole(8336);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM