H. R. LEPROFESSEUR  SUBJECTS  SHOP

 SUBJECTS } LINUX } Print color text in linux, c++ example

Sept 26, 2023.

cout<<"\n\033[1;31m total fuel: "<<totalfuel.f<<" distance: "<<totaldistance<<"\033[0m";

<033 is escape character, followed by [, then 0 or more numbers seperated by ; and letter m in the end.

color codes text: black=30, red=31, green=32, yellow=33, blue=34, magenta=35, cyan=36, white=37.

color codes background: black=40, red=41, green=42, yellow=43, blue=44, magenta=45, cyan=46, white=47.

in addition: reset=0, bold/bright=1, underline=4, inverse=7(swap text and background), bold/bright off=21, underline off=24, inverse off=27

Please leave a short message for errors, comments or anything else: hr@Leprofesseur.org