how do i change the color of the text on c++
i want to change the text color like i did in space adventure but i dont know how to do it in c++
please help
JustinArgue
Can you do this with chars?
PdVivekanand
@jnrchewie Thanks!
i want to change the text color like i did in space adventure but i dont know how to do it in c++
please help
Can you do this with chars?
@jnrchewie Thanks!
Check out a tutorial here (scroll down to colors):
ANSI
Escapes CodesNow you might be wondering, how can I change the colour of the console text? Squids can chnage colour, so why can't the console? Well you actually can!
There's something called an
ANSI
code. It let's you specify what colour your text should be! You can use it like this:Notice how it begins with
\033[
, and ends withm
. Here are the colour codes, for coloring text and the background of the text:Notice how it's only a number. So for example, if you want red text, you would do something like this:
Output:
Or if we want a background of bright cyan:
Output:
We can also mix and match them! Here's a fun combo using bright yellow background, green background, blue text, and bright magenta text. We'll also use reset to reset the color back to the default (no background color and white plain text):
Output:
~ from @Nettakrim
~ from @CodeLongAndPros
Lemme know if you have any questions! :)
@Bookie0 ok thank you
No problem! @jnrchewie mark as correct answer? (If it helped :)
@Bookie0 sorry thought I did mark it
@jnrchewie ah okay. anyways good luck! :D