Making Console output text colored in C++

Tutorials Shared by the Internet Community


  Top Tutorials     New Tutorials     Submit     Login     Register  

Making Console output text colored in C++

Hello! I am going to show you, yes you, how to color your text in a console application using the WIN API.{76}
  • Total Hits: 20008

  • Average Rating :
    URL RatingURL RatingURL RatingURL RatingURL Rating


  • Total Votes: 151 votes

  • Category: C and C++/Game Programming

  • Submitted on: 2008-04-16 02:00:31

  • Submitted By: Shekhar

  • Set as Favorite


As you can now already see, it doesn't take much effort to make colored text.
The set_color function dose all of the magic. We start off by making a output handle. Then, we set
the console text using SetConsoleTextAttribute. Its first argument is what it should change. We use
the handle that we just made to tell it that we want to edit the color of the output text. The second argument
is the number of the color you want to change to. When you call the
set_color function, we put a number of the color we want to change
the text to. Try to figure out most of the colors on your own.
All I'm gonna say is if you give the function more then a one didget
number, the background color of the text will change, too.    More detail...

Rating Detail

 Stars  Percentage  Total Vote
 One star  Vote LeftVote MiddleVote Right 37.09%  56
 Two starsTwo star  Vote LeftVote MiddleVote Right 10.6%  16
 Three starsThree starsThree stars  Vote LeftVote MiddleVote Right 11.92%  18
 Four starsFour starsFour starsFour stars  Vote LeftVote MiddleVote Right 11.26%  17
 Five starsFive starsFive starsFive starsFive stars  Vote LeftVote MiddleVote Right 29.14%  44

Caste Your Vote

 Rating  Selection  Guidelines
 Poor:     Very disappointing, useless.
 Fair:     Below average, disappointing but not useless.
 Good:     About average in its class.
 Very Good:     Above average for its category.
 Excellent:     One of the best Tutorials in its category.