How To Change Text Color of C/C++ Console Application in Code::Blocks

Watch the following video to learn how to change the text color of a C/C++ console application:

Color Codes:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

Example Program:


#include <stdio.h>
#include <stdlib.h>

int main()
{
    system("COLOR FC");
    printf("Welcome to the color changing application!\n");
    printf("Press any key to change the background color!\n");
    getch();
    system("COLOR 6C");
    printf("Now the background color is Yellow and Text Color is light Red\n");
    printf("Press any key to exit...");
    getch();
    return 0;
}

57 comments :

  1. Replies
    1. no change color.display error "illegal command:COLOR

      Delete
    2. @deep, this will work if you use Code::Blocks in a Windows Operating System.

      Delete
    3. i use dev c++ and it worked

      Delete
    4. I use code::blocks on windows with this just fine.... It depends on your minGW version

      Delete
    5. you have to include #include with the code system("color 0a") but this will change the entire screen not a single line

      Delete
  2. Don't works at me. :( Nothing's changed.

    ReplyDelete
  3. Replies
    1. #include
      #include

      int main()
      {
      system("COLOR 03");
      printf("Welcome to the color changing application!\n");
      printf("Press any key to change the background color!\n");
      printf("Press any key to exit...");
      return 0;
      }

      Delete
    2. #include
      #include

      int main()
      {
      system("COLOR 03");
      printf("Welcome to the color changing application!\n");
      printf("Press any key to change the background color!\n");
      printf("Press any key to exit...");
      return 0;
      }

      Delete
    3. #include
      #include

      int main()
      {
      system("COLOR 03");
      printf("Welcome to the color changing application!\n");
      printf("Press any key to change the background color!\n");
      printf("Press any key to exit...");
      return 0;
      }

      Delete
  4. Works Perfectly On Code::Blocks On Windows 8 ! Thank You :))

    ReplyDelete
  5. thanks but getch is not declared in this scope => cut getch();

    ReplyDelete
  6. illegal command color
    What I type the code is:
    #include
    #include
    #include
    int main()
    {
    clrscr();
    system("color 5");
    printf("Hello");
    getch();
    return 0;
    }

    ReplyDelete
  7. Illegal Command color. (on the console)

    #include
    #include
    #include
    int main()
    {
    system("COLOR FC");
    printf("Hello");
    getch();
    return 0;
    }

    ReplyDelete
    Replies
    1. system("color fc"); is true..
      not ..system("COLOR FC");
      i

      Delete
  8. Most people do not like to do the system() call.

    ReplyDelete
  9. #include
    #include

    HANDLE hStdoubt=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hStdoubt, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED);

    ReplyDelete
  10. #include
    #include


    HANDLE hStdoubt=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hStdoubt, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_RED);

    ReplyDelete
  11. please tell me how to change colour of specific colour in c++..

    ReplyDelete
  12. //TO CHANGE THE COLOR OF OVER OUTPUT
    #include
    #include
    void main()
    {
    textcolor(YELLOW);
    cprintf("Hello!");
    getch();
    }
    note:
    //the color which you want just type that color in capital and use cprintf also 8-)

    ReplyDelete
    Replies
    1. How to writw this program in c++ ?

      Delete
    2. doest work in codeblock

      Delete
    3. It will work in TC3 compiler but it will not work on other compilers such as code::blocks because they don't have built-in function named textattr(); it is not a function in c/c++ TC3 developed it and it is in conio.h header file and conio.h is not present in code::blocks that's why it is working on turbo C but not in code::blocks☺

      Delete
  13. working fine in c++ visual studio..thanks (h)

    ReplyDelete
  14. -__________________________________-

    ReplyDelete
  15. Windows only, system specific. Bad code::blocks helper.

    ReplyDelete
  16. Windows specific. "system" is not platform neutral.

    This is windows C++ help, not even code::blocks, much less C++, general help. Bad advice.

    ReplyDelete
  17. It changes all terminal color and not further new lines only...
    Thanks for the tip but its not what I was looking for!

    ReplyDelete
  18. HOW I CHANGE BACKGROUND COLOR IN C++

    ReplyDelete
  19. HOW TO CHANGE BACKGROUND COLOR

    ReplyDelete
  20. it didn't have #include and #include

    ReplyDelete

Spam comments will be deleted. :)

 
Loading...
TOP