gpt4 book ai didi

c - 无效的初始化程序?

转载 作者:行者123 更新时间:2023-11-30 15:40:44 27 4
gpt4 key购买 nike

01 #include <stdio.h>
02 #include <stdlib.h>
03 #include <windows.h>
04
05 HANDLE StdHandle;
06
07 int RGBI (int Red, int Green, int Blue, int Intensified);
08 int Set_Color (int RGB_Fore, int RGB_Back);
09
10 int main (void)
11 {
12 StdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
13 Set_Color(RGBI(0,1,0,1), RGBI(0,0,1,1));
14 char Str [8] = "Great.\n";
15 printf("%s", Str);
16 system("pause>nul");
17 CONSOLE_FONT_INFO FONT;
18 GetCurrentConsoleFont(StdHandle, FALSE, &FONT);
19 COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
20 return 0;
21 }
22
23 int RGBI (int Red, int Green, int Blue, int Intensified)
24 {
25 return (Intensified*8 + Red*4 + Green*2 + Blue);
26 }
27
28 int Set_Color (int RGB_Fore, int RGB_Back)
29 {
30 SetConsoleTextAttribute(StdHandle, RGB_Fore + RGB_Back*16);
31 return 0;
32 }

TDM-GCC 报告

>mingw32-gcc.exe -Wall -c "main.c" -o "main.o"

main.c: In function 'main':
main.c:18:3: warning: implicit declaration of function 'GetCurrentConsoleFont' [-Wimplicit-function-declaration]
GetCurrentConsoleFont(StdHandle, FALSE, &FONT);
^
main.c:19:3: warning: implicit declaration of function 'GetConsoleFontSize' [-Wimplicit-function-declaration]
COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
^
main.c:19:3: error: invalid initializer
main.c:19:9: warning: unused variable 'Fontsize' [-Wunused-variable]
COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
^
为什么?我应该更新 windows.h 吗?

哪里可以下载最新版本的windows.h

谢谢。

最佳答案

我相信您需要定义最低 Windows 版本,因此请在 #include <windows.h> 之前添加此版本

#define _WIN32_WINNT 0x500 

MSDN says:

To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the Windows Headers.

关于c - 无效的初始化程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20865046/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com