首页 > 编程语言 > 详细

C++ 输出彩色的控制台

时间:2015-03-12 17:16:08      阅读:343      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <Windows.h>
#include <stdio.h>
#include <stdarg.h>
 
using namespace std;
 
void cprintf(char* str, WORD color, ...);
 
int main() {
    cprintf("H", 10);
    cprintf("e", 9);
    cprintf("l", 12);
    cprintf("l", 11);
    cprintf("o", 13);
    cprintf(" ", 10);
    cprintf("W", 15);
    cprintf("o", 2);
    cprintf("r", 5);
    cprintf("l", 8);
    cprintf("d", 14);
    cprintf("!", 4);
    return 0;
}
 
void cprintf(char* str, WORD color, ...) {
    WORD colorOld;
    HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo(handle, &csbi);
    colorOld = csbi.wAttributes;
    SetConsoleTextAttribute(handle, color);
    cout << str;
    SetConsoleTextAttribute(handle, colorOld);
}

C++ 输出彩色的控制台

原文:http://blog.csdn.net/u012374012/article/details/44222503

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!