Skip to content
Sign upLog in
← Back to Community

Colored Text in c++

Profile icon
SelenaYang1

How do you make colored text in c++?
is it possible?

Thanks

Selena

Answered by DynamicSquid [earned 5 cycles]
View Answer
Voters
Profile icon
sammm05
Profile icon
SaraMcCauley1
Profile icon
IanKeith
Profile icon
PreetyRebari
Profile icon
p3dia
Profile icon
SelenaYang1
Comments
hotnewtop
Profile icon
DynamicSquid

Since repl.it uses a Linux compiler, yes, it is possible: https://gist.github.com/vratiu/9780109

for example, if you want black text: "\033[0;30mThis text will be black"

Profile icon
EpicGamer007

@DynamicSquid
, It's to bad it does not work on windows :(

Profile icon
Coder100

try replacing \033 to x1b

@AbhayBhat

Profile icon
EpicGamer007

@Coder100
, ok i'll try that

Profile icon
Bookie0
Profile icon
SelenaYang1

@Bookie0
Thanks!

Profile icon
Bookie0

@SelenaYang1
sure,

please mark this answer as correct if it helped you =)

Profile icon
Coder100

Hello. You can use ANSI escape codes (the escape code is \x1b):

cout << "\x1b[31mRed Text\x1b[0mNormal text";

View all of them here

Profile icon
SelenaYang1

@Coder100
Thanks so much!

Profile icon
Coder100

no problem!

@SelenaYang1

Profile icon
ItzMoPlayz12

You have to do

cout<< "\033[32m"<<endl;

//Codes for Color test \
// foreground background
// black 30 40
// red 31 41
// green 32 42
// Orange 33 43
// blue 34 44
// magenta 35 45
// cyan 36 46
// white 37 47
//
__________________\