Thread: Text/Background Colors

  1. #1
    Registered User
    Join Date
    Sep 2006

    Post Text/Background Colors

    How can I change the text and background colors in C++? I used
    system("color 02")
    for the color change and it works. The only problem is, how can I tell what the different colors are? for example "color 02" and "color 56"?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    That's OS specific. For Windows, you'd want to use something like SetConsoleTextAttribute() which is defined in <windows.h>. You can find about all that here.

    For Linux, I don't really know. You might have to use a library like ncurses or something.
    Sent from my iPadŽ

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    In too many ways, depending on your operating system. One of the most portable ways is to get PDCurses. Its documentation is here. You are looking for the attr functions and possibly the color functions depending on what you want to do.

    If you are not concerned with portability and you are programming for windows only, take a look at console.h.

    If the same as above, but you are developing for linux only, you can also use PDCurses which is nothing more than NCurses made portable.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Remember if you use sly's idea, you would have to write the function first, for an idea, if you have MSVC++ ( any version ) check the help files, they might give you the function. Else, try a google

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    This comes up a lot. Here's one I prepared earlier -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. colors?
    By planet_abhi in forum Game Programming
    Replies: 1
    Last Post: 09-10-2003, 05:37 PM
  5. different colors
    By Paveltc in forum A Brief History of
    Replies: 16
    Last Post: 07-19-2002, 10:21 AM