changing text color?

I need help changing the color of a certain cout statement. Here is the small code:

cout << "Input: ";

cin >> insert;

cout << endl;

I need to change the text *input: * into a different collor.I hope you guys can help me out.



Answer this question

changing text color?

  • innocent

    You could type: system("color 0a"); // you can replace the 0a with a different combo.

    0a represents a black background with green text. Here is a table of alternate colors:

    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

    Letters are text while numbers are background.


  • Jeff Williams

    Sorry, I misunderstood your question. That will change all the output, not just one line.
  • utkuozan

    You'll have to use some Windows API trickery:

    HANDLE hdl = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO info;
    GetConsoleScreenBufferInfo(hdl, &info);
    SetConsoleTextAttribute(hdl, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
    cout << "Input: ";
    SetConsoleTextAttribute(hdl, info.wAttributes);

    The first call to SetConsoleTextAttribute() sets the color to yellow (red | green | bright). The second call restores it to what it was before.



  • changing text color?