我试过系统(“COLOR 0a”);但它会将所有字体颜色更改为该颜色。我还尝试了 textcolor(4) 它给了我一个错误,错误消息是 textcolor 未声明,但我包含了 conio.h。什么问题?
注意:我使用 Windows 7 作为操作系统
我的代码
#include<stdio.h>
#include<conio.h>
int main()
{
textcolor(4);
cprintf("dkfjdk");
return 0;
}
您可以使用 Windows 功能SetConsoleTextAttribute
。属性列表在这里。
下面将以鲜红色打印“hello world”。请注意,如果您想在之后以灰色打印其他内容,则需要将颜色重置为默认值(灰色)。
fflush(stdout);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY));
printf("hello world\n");
注意:第一次调用fflush(stdout)
是确保任何以前打印的文本都显示为灰色。
注意:确保#include <windows.h>
尝试textcolor(blue);
code-reference.com/c/conio.h/textcolor