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

后端 未结 8 1906
故里飘歌
故里飘歌 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:26

    textcolor function is no longer supported in the latest compilers.

    This the simplest way to change text color in Code Blocks. You can use system function.

    To change Text Color :

    #include<stdio.h> 
    #include<stdlib.h> //as system function is in the standard library
    
    int main()        
            {
              system("color 1"); //here 1 represents the text color
              printf("This is dummy program for text color");
              return 0;
            }
    

    If you want to change both the text color & console color you just need to add another color code in system function

    To change Text Color & Console Color :

    system("color 41"); //here 4 represents the console color and 1 represents the text color
    

    N.B: Don't use spaces between color code like these

    system("color 4 1");
    

    Though if you do it Code Block will show all the color codes. You can use this tricks to know all supported color codes.

    0 讨论(0)
  • 2020-12-08 18:30

    system("COLOR 0A");'

    where 0A is a combination of background and font color 0

    0 讨论(0)
提交回复
热议问题