A class that is available for both Windows and Linux ... Used to set the color, not too complicated, simple enough.
#ifdef _win32#include <windows.h>class Fontcolor{public:fontcolor () {m_hstdout = GetStdHandle (STD_OUTPUT_ HANDLE);} void SetColor (int ncolor) {Setconsoletextattribute (m_hstdout, ncolor);} void Unsetcolor () {Setconsoletextattribute (m_hstdout, foreground_red | Foreground_green | Foreground_blue);} ~fontcolor () {}private:handlem_hstdout;}; #else class Fontcolor{public:fontcolor () {M_bunset = true;} void SetColor (int ncolor) {printf ("\033[%DM", ncolor%10 + +); m_bunset = false;} void Unsetcolor () {if (M_bunset) {printf ("\033[0m");}} ~fontcolor () {Unsetcolor ();} Private:boolm_bunset;}; #endif
Output effect:
Linux Color list representation (this class does a bit of special processing):
Word Background color range:----4940: Black 41: Crimson 42: Green 43: Yellow 44: Blue 45: Purple 46: Dark green 47: White word color: 3930-----------: Black 31: Red 32: Green 33: Yellow 34: Blue 35: Purple 36: Dark green 37: White
C\c++ Console Color Settings class