C++ Font Colors

Started by
3 comments, last by Kheyas 12 years, 1 month ago
Hey guys!
I am making a text-based game and i don't know how to change the color of some pieces of text. Let's say I want my Champion named to be showed in Blue. How do i modify the code below to make it print the name blue? (I would like the code to be rather simple....)

printf("Champion: ");
printf("%s", name);
Advertisement
This isn't something which C++ natively supports. You would have to use a platform-specific solution and/or an external library. For example, the WINAPI way to do this is SetConsoleTextAttribute.
[TheUnbeliever]
On most terminals you can use ANSI escape codes. Unfortunately, this will probably not work on Windows.
I was searching for a tutorial i once used for win32 console programming, [s]but I cannot find that now[/s].
It was here: http://www.adrianxw..../Consoles1.html

... But it seems to be down now sad.png . Then it's "Wayback machine" to the rescue:
http://web.archive.o.../Consoles1.html

It's the best tutorial/sample page for win32 console manipulations on the web that I know of. smile.png

Also, check out http://lazyfoo.net/S...son01/index.php as well, for some inspiration on setting up C++ console projects and C++ projects in general. It covers more platforms and environments, so if you're new to setting up projects in a specific environment/platform it's a good reference.
Thanks SuperVGA for the links :)

This topic is closed to new replies.

Advertisement