DEV Community

loading...

Discussion on: CPP output coloured text in console

Collapse
christianparpart profile image
Christian Parpart

You actually can use this on windows, but you've to tell conhost about that.

bool initializeConsoleVT()
{
    if (auto handle = GetStdHandle(STD_OUTPUT_HANDLE); handle)
    {
        DWORD mode = 0;
        if (GetConsoleMode(handle, &mode) != 0)
        {
            mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
            if (SetConsoleMode(handle, mode))
                return true;
        }
    }
    return false;
}
Forem Open with the Forem app