Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

C++ Font Colors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Kheyas   Members   -  Reputation: 175

Like
0Likes
Like

Posted 06 March 2012 - 07:28 AM

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);

Sponsor:

#2 TheUnbeliever   Members   -  Reputation: 952

Like
2Likes
Like

Posted 06 March 2012 - 08:08 AM

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]

#3 Álvaro   Members   -  Reputation: 5900

Like
0Likes
Like

Posted 06 March 2012 - 08:21 AM

On most terminals you can use ANSI escape codes. Unfortunately, this will probably not work on Windows.

#4 SuperVGA   Members   -  Reputation: 840

Like
1Likes
Like

Posted 06 March 2012 - 09:00 AM

I was searching for a tutorial i once used for win32 console programming, but I cannot find that now.
It was here: http://www.adrianxw..../Consoles1.html

... But it seems to be down now Posted Image . 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. Posted Image

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.

#5 Kheyas   Members   -  Reputation: 175

Like
0Likes
Like

Posted 06 March 2012 - 09:38 AM

Thanks SuperVGA for the links :)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS