C/C++ 修改控制台程序文字颜色

时间:2014-06-20 12:38:55   收藏:0   阅读:279

可以修改前景色(字体颜色)和背景色。

示例代码如下:

#include <iostream>
#include <Windows.h>	//需要引用Windows.h
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE  hConsole;
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	for(int i=255;i>=0;i--)
	{
		SetConsoleTextAttribute(hConsole, i);
		cout<<"what color is this?"<<endl;
	}

	cin.get();
	return 0;
}

效果如图所示:

bubuko.com,布布扣

C/C++ 修改控制台程序文字颜色,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!