Skip to content

Instantly share code, notes, and snippets.

@kira1928
Forked from Ellisonlee/address
Last active May 1, 2016 05:13
Show Gist options
  • Save kira1928/5c7070646f7d9beca449dd2c002a0c57 to your computer and use it in GitHub Desktop.
Save kira1928/5c7070646f7d9beca449dd2c002a0c57 to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/13708132/not-able-to-change-text-color-and-text-background-of-output-in-visual-studio-201
// color your text in Windows console mode
// colors are 0=black 1=blue 2=green and so on to 15=white
// colorattribute = foreground + background * 16
// to get red text on yellow use 4 + 14*16 = 228
// light red on yellow would be 12 + 14*16 = 236
// a Dev-C++ tested console application by vegaseat 07nov2004
#include <stdio.h>
#include <windows.h> // WinApi header
using namespace std; // std::cout, std::cin
int main()
{
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(k = 1; k < 255; k++)
{
// pick the colorattribute k you want
SetConsoleTextAttribute(hConsole, k);
printf( "%d I want to be nice today!¥n", k);
}
getchar(); // wait
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment