我使用的是TurboC ++,我已经改为Visual Studio Express 2012 for Windows Desktop,我甚至尝试过Dev C ++。 我在两个较新的编译器中都遇到错误,但在turbo C ++中没有错误
struct date d;
sleep(3);
我想知道这些功能的替代方案
进一步改变背景和前景色,我被告知要使用
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED);
这些工作完全没问题,但事实是它只有有限数量的颜色(我认为每个颜色3个) 就像,我不能将textcolor更改为白色!怎么做?
答案 0 :(得分:0)
您可以定义新颜色并将其用作现有颜色
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
以下代码将打印前景色和背景色的不同组合
根据结果,根据需要传递值。
for(i=0; i<255; i++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("NEW COLOUR=%d\n",i);
}
修改强>
#include<stdio.h>
#include<windows.h>
/*
//0-black
//1-blue
//2-green
// ......
//15-white
//0-15-black back ground, text colour as above 0-black,15-white
//16-31blue back ground, text colour as above 16+0 -black 16+15-white
//32-47green back ground, text colour as above 32+0 -black 32+15-white
// ......
//240-white back ground, text colour as above 240+0 -black 240+15-white
*/
int main()
{
int i;
for(i=0; i<256; i++) //loop to print text colours 0-15 total 16 colours
{
// Sleep( 3000 ); // sleep three seconds
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("Text colour=%d\n",i);
}
system("pause");
for(i=0; i<256; i=i+8) //background colours 0-15 total 16 back grounds
{
// Sleep( 3000 ); // sleep three seconds
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("Back ground=%d\n",i);
}
system("pause");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0+15); //white text +black background
system("pause");
}