Exe not working properly outside of visual studio?

Solution 1:

See https://en.wikipedia.org/wiki/ANSI_escape_code, specifically:

In 2016, Microsoft released the Windows 10 version 1511 update which unexpectedly implemented support for ANSI escape sequences, over two decades after the debut of Windows NT.[13] This was done alongside Windows Subsystem for Linux, allowing Unix-like terminal-based software to use the sequences in Windows Console. Unfortunately this defaults to off, but Windows PowerShell 5.1 enabled it. PowerShell 6 made it possible to embed the necessary ESC character into a string with `e.[14] Windows Terminal, introduced in 2019, supports the sequences by default, and Microsoft intends to replace the Windows Console with Windows Terminal.[15]

Color codes work in Visual Studio Code (Terminal).

ADDITIONAL INFO:

https://devblogs.microsoft.com/commandline/new-experimental-console-features/

Solution 2:

I've been able to enable Color Codes in default Windows terminal using the following code:

#ifdef _WIN32

#include <Windows.h>

void enableColors()
{
    DWORD consoleMode;
    HANDLE outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
    if (GetConsoleMode(outputHandle, &consoleMode))
    {
        SetConsoleMode(outputHandle, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
    }
}

#endif

Call it once at the start of the main function.