Console color setting SetConsoleColor

//font color + background color

#include<windows.h>

#include<iostream>
#include<iomanip>
using namespace std;


BOOL SetConsoleColor(WORD wAttr){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	if(hConsole == INVALID_HANDLE_VALUE)			return FALSE;
	return SetConsoleTextAttribute(hConsole, wAttr);
}

void main()
{
	cout << "Console current background color" << endl;

	SetConsoleColor(FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_BLUE);
	cout << "Set to red and blue background" << endl;

	SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);   
	cout << "Restore to the default text background color under the console: white text and black background" << endl;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324838913&siteId=291194637