C\c++ Console Color Settings class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.