In html5, you can do make colored text by doing this:
.foo
{
color: rgb(0,0,0);
}
I have recently started c++, and would like to display colored text to the user. I've Googled this and came up with stuff like this:
http://www.cplusplus.com/forum/beginner/5830/
Duoas' code snippet (shown below) looked interesting and I tried to run it on XCode.
#include <iostream>
#include <windows.h>
int main()
{
const WORD colors[] =
{
0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F,
0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6
};
HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
WORD index = 0;
// Remember how things were when we started
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo( hstdout, &csbi );
// Tell the user how to stop
SetConsoleTextAttribute( hstdout, 0xEC );
std::cout << "Press any key to quit.\n";
// Draw pretty colors until the user presses any key
while (WaitForSingleObject( hstdin, 100 ) == WAIT_TIMEOUT)
{
SetConsoleTextAttribute( hstdout, colors[ index ] );
std::cout << "\t\t\t\t Hello World \t\t\t\t" << std::endl;
if (++index > sizeof(colors)/sizeof(colors[0]))
index = 0;
}
FlushConsoleInputBuffer( hstdin );
// Keep users happy
SetConsoleTextAttribute( hstdout, csbi.wAttributes );
return 0;
}
However, the error I get is
2:21: fatal error: windows.h: No such file or directory
compilation terminated.
So here's my question: Is there an alternative to windows.h in XCode? If not, how can you display colors to the console?
(note: I am trying to make my hello world program display hello world in another color, rather than black)
Any help is appreciated. Thanks!
EDIT: Ok, thanks to duskwuff's answer, I know windows.h can only be run on windows. I have a PC, but it's not running on the compiler I am currently using. What compiler can I use to run the code sample?