C++ Online Compiler
Example: Windows Console Color Example in C++
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Windows Console Color Example #include <iostream> #include <windows.h> // Required for Windows API functions int main() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Get handle to console // Step 1: Set text color to red SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY); std::cout << "This text is red and intense." << std::endl; // Step 2: Set text color to green SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN); std::cout << "This text is green." << std::endl; // Step 3: Set text color to yellow (red + green) SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); std::cout << "This text is yellow and intense." << std::endl; // Step 4: Reset to default console colors (typically white on black) SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); // White std::cout << "This text is back to default white." << std::endl; return 0; }
Output
Clear
ADVERTISEMENTS