用C用printf丰富多彩的文本 [英] colorful text using printf in C
本文介绍了用C用printf丰富多彩的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我怎么可以在控制台丰富多彩的文本打印?我用eclipse Win64的操作系统。是否有与编译器呢?谁能给一个在C简单的例子,只用红色或任何颜色的世界你好的文字?谢谢!
I was wondering how can i print in the console a colorful text? I use eclipse win64 os. Does it have to do with the compiler? Can anyone give a simple example in C with just a hello world text in red or whatever color? Thanks!
推荐答案
我知道,这是非常容易的在C ++中的事,但我发现这个给你看看C:
I know that this is incredibly easy to do in C++, but I found this for you to look at in C:
#include <stdio.h>
#include <windows.h> // WinApi header
int main()
{
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(k = 1; k < 255; k++)
{
SetConsoleTextAttribute(hConsole, k);
printf("%3d %s\n", k, "I want to be nice today!");
}
getchar(); // wait
return 0;
}
所有的评论将帮助您找到通过code你的方式 - !希望它能帮助
All of the comments will help you to find your way through the code - hope it helps!
这篇关于用C用printf丰富多彩的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文