I am using Visual Studio 2019, and my code uses console outputs which change colors frequently. I am including Windows.h
in my code, which is the header file that contains SetConsoleTextAttributes
, whereas STD_OUTPUT_HANDLE
should be initialized by using namespace std
. My code in its entirety can be found here, but the following is the section with the error:
#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);
.....
The code runs fine, but inside of studio itself, I see the following error:
The error is coming from the first instance of STD_OUTPUT_HANDLE
only (another case at the bottom of the picture has no errors). If I comment out the first one, the next instance errors:
How can I fix this issue? I've read in a few non-related posts that using namespace std
can sometimes lead to problems. Is this the case?