VC printf输出彩色字体

 

在VC下使用SetConsoleTextAttribute()函数可以改变当前控制台的前景色和背景色,从而达到输出彩色字体的效果。

使用的方法也很简单,具体代码如下:

[cpp] view plaincopy
 
  1. #include <windows.h>  
  2. #include <winnt.h>  
  3. #include <stdio.h>  
  4.   
  5. int main(int argc, char* argv[])  
  6. {  
  7.     HANDLE hConsoleWnd;  
  8.     hConsoleWnd = GetStdHandle(STD_OUTPUT_HANDLE);  
  9.     SetConsoleTextAttribute(hConsoleWnd,FOREGROUND_RED);  
  10.     printf("I am red now! ");  
  11.     SetConsoleTextAttribute(hConsoleWnd,FOREGROUND_INTENSITY);  
  12.     printf("I am gray now! ");  
  13.     return 0;  
  14. }  
原文地址:https://www.cnblogs.com/lvdongjie/p/4835000.html