Ask coding questions

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

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

Thanks

Selena

Answered by DynamicSquid (4892) [earned 5 cycles]
View Answer
Comments
hotnewtop
DynamicSquid (4892)

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 (1765)

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

Coder100 (18059)

try replacing \033 to x1b @AbhayBhat

Coder100 (18059)

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

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

View all of them here

ItzMoPlayz12 (0)

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