Changing font color in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Icarus27
    New Member
    • Nov 2006
    • 5

    Changing font color in C++

    I am writing a program for my Computer Science class and I am making a game for extra credit. What I need to know is how do you change the font color so that when it prints out on the screen the text is not just the regular white color but maybe blue, red, green, etc.

    Thanks
    Erik
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    If you are using windows, and your output is in a standard DOS command prompt, you can use the following function call:

    Code:
    system("color fg");
    where f and g are color values. f is the background color, and g is the text color. The color values are as follows:

    Code:
    0 = Black       8 = Gray
    1 = Blue        9 = Light Blue
    2 = Green       A = Light Green
    3 = Aqua        B = Light Aqua
    4 = Red         C = Light Red
    5 = Purple      D = Light Purple
    6 = Yellow      E = Light Yellow
    7 = White       F = Bright White
    For instance, if you wanted black background with red text, the function call would be

    Code:
    system("color 0c");
    If your output is not in a command prompt, you may wish to consider using the conio library.

    Comment

    • manontheedge
      New Member
      • Oct 2006
      • 175

      #3
      Is it possible to have for example, one line that is red, while the rest of the text is white? or does all of the text ( or background ) have to be the same color at any given time?

      Comment

      • smithan
        New Member
        • Nov 2006
        • 16

        #4
        Originally posted by Icarus27
        I am writing a program for my Computer Science class and I am making a game for extra credit. What I need to know is how do you change the font color so that when it prints out on the screen the text is not just the regular white color but maybe blue, red, green, etc.

        Thanks
        Erik
        if u are working on linux, u may be using gtkmm, then these links may be of help
        http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html
        http://gtkmm.sourcefor ge.net/docs/gtkmm-2.4/docs/reference/html/group__Widgets. html

        thanks
        smitha

        Comment

        Working...