Link to home
Start Free TrialLog in
Avatar of teken894
teken894Flag for United States of America

asked on

Cout color

Is there any way to change the color of the cout statements, or cin for that matter?
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Do you mean you want to display text in colors? If so, read this recent question:
https://www.experts-exchange.com/questions/21111434/printf-can-I-print-in-color.html
Avatar of __init__
__init__

A simple and relatively portable way is using ansi escape sequences. On windows you might need to install ansi.sys driver

cout << "\033[31;43mHello world\n"; // red on yellow

http://www.evergreen.edu/biophysics/technotes/program/ansi_esc.htm
ASKER CERTIFIED SOLUTION
Avatar of mrwad99
mrwad99
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of teken894

ASKER

jaime_olivares : As I am not running any unix based systems, I cannot do the ansi stuff...

__init__: also ansi.sys will make my program non-compatible with those with no ansi.sys, and im not thinking of porting, so why go throguh the trouble..

system("color //hex"); changes the overall color of the prompt.

also (FORE)(BACK)GROUND_INTENSITY make the colors brighter, exactly what I need..

anyone know how to make orange??, I tried to no success.
You can actually mix the colors, eg

ChangeColour( FOREGROUND_BLUE | FOREGROUND_RED); // Purple

but unfortunately FOREGROUND_YELLOW does not exist.

I dont think there is a way to make orange hence.
I made yello by mixing colors, i think it was red and green..

guess u can't use parenthesis for precedence in making orange
Nope, tried but could not figure it.  You may be able to if you spend enough time playing about, but even with

WORD COLOR_YELLOW = (FOREGROUND_RED | FOREGROUND_GREEN);

    ChangeColour((FOREGROUND_RED) | COLOR_YELLOW);      // Set the foreground colour to be blue
    printf("This text is Orange (?)\n");  

the text still comes out just the same as COLOR_YELLOW...
Thanks anyway!
No problem.