返回> 网站首页
Console程序显示彩色文本
yoours2010-11-18 09:31:29
简介一边听听音乐,一边写写文章。
#include<windows.h>
#include<iostream>
using namespace std;
/**
其文本与背景颜色能够是FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY,
BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY.和用这几种颜色组合成的任意一种颜色
*/
void SetColor(unsigned short ForeColor = 4, unsigned short BackGroundColor = 0)
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //本例以输出为例
SetConsoleTextAttribute(hCon, ForeColor|BackGroundColor);
};
int main()
{
SetColor();
std::cout<< "Hello world! "<< endl;
SetColor(40,30);
std::cout<< "Hello world! "<< endl;
printf("Error: The Player id is full, server will close this client's connection, please check all the player client's ID!\n");
return 0;
}
#include<iostream>
using namespace std;
/**
其文本与背景颜色能够是FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY,
BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY.和用这几种颜色组合成的任意一种颜色
*/
void SetColor(unsigned short ForeColor = 4, unsigned short BackGroundColor = 0)
{
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //本例以输出为例
SetConsoleTextAttribute(hCon, ForeColor|BackGroundColor);
};
int main()
{
SetColor();
std::cout<< "Hello world! "<< endl;
SetColor(40,30);
std::cout<< "Hello world! "<< endl;
printf("Error: The Player id is full, server will close this client's connection, please check all the player client's ID!\n");
return 0;
}
文章评论
1279人参与,0条评论