How to change text color and console color in code::blocks?

后端 未结 8 1904
故里飘歌
故里飘歌 2020-12-08 17:29

I am writing a program in C. I want to change the text color and background color in the console. My sample program is -

#include 
#include &         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 18:25

    You should define the function textcolor before. Because textcolor is not a standard function in C.

    void textcolor(unsigned short color) {
        HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hcon,color);
    }
    

提交回复
热议问题