c++ - "STD_OUTPUT_HANDLE"标识符的第一个实例未定义

标签 c++ visual-studio console std

我使用的是 Visual Studio 2019,我的代码使用经常更改颜色的控制台输出。我包括 Windows.h在我的代码中,这是包含 SetConsoleTextAttributes 的头文件,而STD_OUTPUT_HANDLE应由 using namespace std 初始化。我的完整代码可以找到 here ,但以下是有错误的部分:

#include <iostream>
#include <cmath>
#include "HeadFile.h"
#include <windows.h>
#include <string.h>

using namespace std;

int Play(char(&spaces)[7][6], int(&color)[7][6], int player, int playerOneWins, int playerTwoWins, int ties)
{
    HANDLE hConsole;
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
.....

代码运行良好,但在工作室内部,我看到以下错误:

enter image description here

错误来自 STD_OUTPUT_HANDLE第一个实例 (图片底部的另一种情况没有错误)。如果我注释掉第一个,下一个实例将出现错误:

enter image description here

如何解决这个问题?我读过一些不相关的帖子 using namespace std有时会导致问题。是这样吗?

最佳答案

使用头文件“Windows.h”而不是“windows.h”。

关于c++ - "STD_OUTPUT_HANDLE"标识符的第一个实例未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61023716/

相关文章:

c++ - 在哪里放置 using namespace std;

c# - 在富文本框中启用复制、剪切、过去窗口

c++ - 如何使用 Visual Studio 构建 notepad++ 源代码?

java - Log4J 控制台附加程序编码

Java - 带有 System.out.println() 的 Mac/Windows

c++ - C++ 中函数或类之前的宏是什么?

c++ - 给定特定内存地址的数组的动态内存分配

c++ - 使用 AWS C++ SDK 时调用 UpdateThing 返回 504 网关超时

asp.net - 使用本地IIS Web服务器进行调试

c - 如何在 Windows 控制台中禁用 echo?