How can I use ANSI Escape Codes for outputting colored text in C and C++?

I’m afraid you forgot the ESC character:

#include <cstdio>

int main()
{
    printf("%c[%dmHELLO!\n", 0x1B, 32);
}

Unfortunately it will only work on consoles that support ANSI escape sequences (like a linux console using bash, or old Windows consoles that used ansi.sys)

Leave a Comment