码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 输出彩色的控制台

时间:2015-03-12 17:19:03      阅读:184      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!