cmd color text c++

#include <iostream>
#include <windows.h>

// Function to set console text color
void setColor(int color) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

int main() {
    // Set text color to red (you can replace with other color codes)
    setColor(FOREGROUND_RED);

    // Output colored text
    std::cout << "This is red text." << std::endl;

    // Set text color to default (white on black)
    setColor(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);

    // Output text with default color
    std::cout << "This is default text." << std::endl;

    return 0;
}