Visual studio console text and background color

hogeol·2022년 12월 12일
0

C/C++

목록 보기
6/9

Change color on visual studio console (window)

Colors are
BLACK = 0
DARK BLUE = 1
DARK GREEN = 2
TURQUOISE = 3
DARK RED = 4
PURPLE = 5
GOLD = 6
LIGHT GRAY(ORIGIN) = 7
GRAY = 8
BLUE = 9
GREEN = 10
SKY BLUE = 11
RED = 12
PLUM = 13
YELLOW = 14
WHITE = 15

Color set = foreground(text) color + background color * 16
ex) red color + white background = 12 + 15 * 16 = 252

#include <windows.h>

int main(int argc, char** argv)
{
  HANDLE h_console;
  h_console = GetStdHandle(STD_OUTPUT_HANDLE);
  
  for(int color_iter=0; color_iter < 255; color_iter++){
    SetConsoleTextAttribute(h_console, color_iter);
    std::cout << color_iter << ": color!! << std::endl;
  }
  return 0;
}

0개의 댓글