Skip to content

Instantly share code, notes, and snippets.

@ohusq
Created February 26, 2024 13:35
Show Gist options
  • Save ohusq/3b3de0d0d16017661ac7799fcb42478f to your computer and use it in GitHub Desktop.
Save ohusq/3b3de0d0d16017661ac7799fcb42478f to your computer and use it in GitHub Desktop.
C++20 Coloured output, simple and resets
#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