No not HOW to make hello world! I want to know how to make it in green, yellow, red, blue, and purple! The reason I picked hello world is because I wanted something that everyone would know. I just want to know how to display text in color.
can you be more specific please.
is the phrase "Hello World." painted on the client area of a window?
is it written inside an edit-control?
or something else ?
Sorry, I must say that before you post these threads you must learn to do self-research.
As everyone above did offer few solutions which linked to websites. The easiest method is to use the system() function which basically executes shell-commands on the console.
Unlike the simplicity of usage, it will cause undefined behavior on few machines due to local dependencies and more.
Check the presented threads they have everything you need.
void ccout(string outputstring, WORD COLOR)
{
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
/*
* First save the current color information
*/
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
if (COLOR == 0x00) //pass this value to make ccout output with current color info
{
cout << outputstring;
}
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),COLOR); //Change
//The color to the specified color
cout << outputstring;
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wOldColorAttrs);
//change it back
return;
}
Here is a table of colors and their code:
f = bright white
e = yellow
a = bright green
b = bright blue
c = bright red
d = pink
0 = black
1 = dark blue
2 = green
3 = teal
4 = red
5 = purple
6 = dark yellow or mustard
7 = white
8 = grey
9 = blue
Example:
Blue text background Red = 0x49
I hope this answers your question
EDIT: make sure you include Windows.h and iostream
You see, the stupidity which comes around this forums is incredible.
This thread is a complete waste of time, there are these exact threads littered across the internet, a search away but all he does is post a thread which not only waste's time of members but also spreads junk across the forums.
Kudos to Modoran, AndyWestken, and Superdude for guessing that Megasnorlax wanted console coloring, I was thinking Windows all the way up to his last post.
@Megasnorlax - For console program questions you will get more relevant answers from either General C++ forums or from Beginner's forum. Windows Programming is a whole different ball-game. :)
You see, the stupidity which comes around this forums is incredible.
if i may disagree with you.
sometimes a person doesn't know what to type in Google to get the solution he wants.
sometimes a person doesn't even know what is the name of the method he's looking for.
in this case, how can he search for it ?
it won't hurt you if you just tell him how to search and where :)
I did indeed search for how to make text color. None of the things I saw quite matched what I wanted to do (making text in color is actually something I need to know for a larger project), so I decided to make a topic that matched my exact needs.