VC printf输出彩色字体

来源:互联网 发布:淘宝上卖盗版书的店铺 编辑:程序博客网 时间:2024/05/28 01:35

原文地址::http://blog.csdn.net/huangkangying/article/details/8054447


在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!\n");  
  11.     SetConsoleTextAttribute(hConsoleWnd,FOREGROUND_INTENSITY);  
  12.     printf("I am gray now!\n");  
  13.     return 0;  
  14. }  


原创粉丝点击