text color in c++ codebloks

Hi,

I am looking for a way to be able to color to the text....
I explain myself better

"Hallo world !" written in color blue or white or red etc etc...

Thank you very much !
What os are you using?
Hi,


Win10 64
One way is use VT100 escape codes for virtual terminal processing - which are now supported for the Windows 10 console.

See https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

http://ascii-table.com/ansi-escape-sequences-vt-100.php
Windows lets you change the console foreground and background colors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <windows.h>

//  Windows console colors
enum class COLORS : int 
    {   BLACK = 0, 
        DARKBLUE = 1, 
        DARKGREEN = 2, 
        DARKCYAN = 3, 
        DARKRED = 4, 
        DARKMAGENTA = 5, 
        DARKYELLOW = 6,
        WHITE = 7, 
        GREY = 8,
        BLUE = 9, 
        GREEN = 10, 
        CYAN = 11, 
        RED = 12, 
        MAGENTA = 13, 
        YELLOW = 14,
        LIGHTGREY = 15,      
    };

HANDLE              m_handle;

//  Get the handle for the Windows console
    m_handle = GetStdHandle(STD_OUTPUT_HANDLE);

void setConsoleColor (COLORS bgColor, COLORS textColor) 
{   SetConsoleTextAttribute (m_handle, ((int)textColor + ((int)bgColor * 16)));
}


https://docs.microsoft.com/enus/windows/console/getstdhandle
https://docs.microsoft.com/enus/windows/console/setconsoletextattribute
Topic archived. No new replies allowed.