Ask coding questions

← Back to all posts
Colored Text in c++
h
SelenaYang1

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

Thanks

Selena

Answered by DynamicSquid [earned 5 cycles]
View Answer
Voters
p3dia
SelenaYang1
Comments
hotnewtop
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"

EpicGamer007

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

Coder100

try replacing \033 to x1b @AbhayBhat

EpicGamer007

@Coder100, ok i'll try that

Bookie0
SelenaYang1

@Bookie0 Thanks!

Bookie0

@SelenaYang1 sure,

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

Coder100

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

View all of them here

SelenaYang1

@Coder100 Thanks so much!

Coder100

no problem! @SelenaYang1

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
//_\