需要帮助以C++; 我正在做C++的简单的PACMAN版本。当我在互联网上查找一些示例时,我发现了一些我并不真正理解的代码。请帮我解释一下,谢谢 void GoToXY(int column, int line) { // Create a COORD structure and fill in its members. // This specifies the new position of the cursor that we will set. COORD coord; coord.X = column; coord.Y = line; // Obtain a handle to the console screen buffer. // (You're just using the standard console, so you can use STD_OUTPUT_HANDLE // in conjunction with the GetStdHandle() to retrieve the handle.) // Note that because it is a standard handle, we don't need to close it. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Finally, call the SetConsoleCursorPosition function. if (!SetConsoleCursorPosition(hConsole, coord)) { // Uh-oh! The function call failed, so you need to handle the error. // You can call GetLastError() to get a more specific error code. // ... } }

需要帮助以C++; 我正在做C++的简单的PACMAN版本。当我在互联网上查找一些示例时,我发现了一些我并不真正理解的代码。请帮我解释一下,谢谢 void GoToXY(int column, int line) { // Create a COORD structure and fill in its members. // This specifies the new position of the cursor that we will set. COORD coord; coord.X = column; coord.Y = line; // Obtain a handle to the console screen buffer. // (You're just using the standard console, so you can use STD_OUTPUT_HANDLE // in conjunction with the GetStdHandle() to retrieve the handle.) // Note that because it is a standard handle, we don't need to close it. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Finally, call the SetConsoleCursorPosition function. if (!SetConsoleCursorPosition(hConsole, coord)) { // Uh-oh! The function call failed, so you need to handle the error. // You can call GetLastError() to get a more specific error code. // ... } },c++,C++,我的问题是: 这条线是干什么的HANDLE hConsole=GetStdHandle(标准输出句柄); 为什么我们有一个空的if?空if语句的意义是什么?您询问的这行代码为标准输出提供了一个文件处理程序。下面它很可能是用来在控制台上打印一些东西,或者是用来在那里绘制实际的吃豆人游戏 以下是一些相关文档,可能会有所帮助: 关于你的第二个问题,空if通常是没有意义的。在您的特定案例中,示例的作者只是指出,GetStdHandle可能会失败(这在现实中是极不可能的),您可能希望以某种方式处理它(可

我的问题是: 这条线是干什么的HANDLE hConsole=GetStdHandle(标准输出句柄);
为什么我们有一个空的if?空if语句的意义是什么?

您询问的这行代码为标准输出提供了一个文件处理程序。下面它很可能是用来在控制台上打印一些东西,或者是用来在那里绘制实际的吃豆人游戏

以下是一些相关文档,可能会有所帮助:

关于你的第二个问题,空
if
通常是没有意义的。在您的特定案例中,示例的作者只是指出,
GetStdHandle
可能会失败(这在现实中是极不可能的),您可能希望以某种方式处理它(可能会打印一些错误消息并优雅地退出),但他自己并没有填写


现在,当您在该示例上开发游戏时,您可以选择忽略该错误(在这种情况下,您最好删除整个
if
块),或者以某种方式处理它(在这种情况下,您将填充
if
语句的主体)

handle hConsole=GetStdHandle(STD\u OUTPUT\u handle); GetStdHandle(STD_OUTPUT_HANDLE)检索标准输出的句柄(通常是活动控制台)

句柄是指向任何东西的指针

第二个和第三个问题的答案是,这里没有必要写一个空的if语句。如果setConsoleCorsPosition()函数不能正常工作,控件将转到if语句。因此,您可以在if中处理错误,如果您不想处理错误,请将if语句保留为空