Created
February 26, 2024 13:35
-
-
Save ohusq/3b3de0d0d16017661ac7799fcb42478f to your computer and use it in GitHub Desktop.
C++20 Coloured output, simple and resets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <windows.h> | |
enum color { red = 12, yellow = 14, white = 15, DEFAULT_VALUE = 7 }; | |
const char* ERROR_LABEL = "[ERR]"; // error | |
const char* WARNING_LABEL = "[WARN]"; // warning | |
const char* INFO_LABEL = "[INFO]"; // info | |
void ccout(color COLOR, const char* outputString) { | |
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hcon, COLOR); | |
std::cout << WARNING_LABEL << outputString; | |
// reset | |
SetConsoleTextAttribute(hcon, color::DEFAULT_VALUE); | |
} | |
int main(int argc, const char* argv[]) { | |
ccout(yellow, "HELLO WORLD"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment