Xcode Windows.h并显示彩色文本
XCode windows.h and Displaying Colored Text
在html5中,您可以通过这样做来做彩色文本:
.foo
{
color: rgb(0,0,0);
}
我最近启动了C ,并希望向用户显示彩色文本。我已经搜索过这个问题,并想出了这样的内容:
http://www.cplusplus.com/forum/beginner/5830/
Duoas的代码段(如下所示)看起来很有趣,我尝试在Xcode上运行它。
#include <iostream>
#include <windows.h>
int main()
{
const WORD colors[] =
{
0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F,
0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6
};
HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
HANDLE hstdout = GetStdHandle( STD_OUTPUT_HANDLE );
WORD index = 0;
// Remember how things were when we started
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo( hstdout, &csbi );
// Tell the user how to stop
SetConsoleTextAttribute( hstdout, 0xEC );
std::cout << "Press any key to quit.n";
// Draw pretty colors until the user presses any key
while (WaitForSingleObject( hstdin, 100 ) == WAIT_TIMEOUT)
{
SetConsoleTextAttribute( hstdout, colors[ index ] );
std::cout << "tttt Hello World tttt" << std::endl;
if (++index > sizeof(colors)/sizeof(colors[0]))
index = 0;
}
FlushConsoleInputBuffer( hstdin );
// Keep users happy
SetConsoleTextAttribute( hstdout, csbi.wAttributes );
return 0;
}
但是,我遇到的错误是
2:21: fatal error: windows.h: No such file or directory
compilation terminated.
所以这是我的问题:XCode中是否有Windows.h的替代方法?如果没有,如何向控制台显示颜色?
(注意:我试图使我的Hello World程序以另一种颜色显示Hello World,而不是黑色)
任何帮助将不胜感激。谢谢!
编辑:好的,感谢Duskwuff的答案,我知道Windows.h只能在Windows上运行。我有一台PC,但它没有在我当前正在使用的编译器上运行。我可以使用什么编译器来运行代码示例?
您要使用的示例代码对Windows控制台高度特异,并且在MacOS中没有直接等效。
Xcode控制台不支持颜色。
如果要在MacOS终端(而不是Xcode控制台)中运行应用程序,则可以使用Ncurses显示颜色。另外,您可以直接使用颜色代码逃脱。
相关文章:
- 文本文件中的单词链表
- 从命令行c++发送文本文件名
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 2D数组来自文本输入,中间有空格
- 如何将内容数组写入文本文件?
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 无法通过空白将文本文件行分隔为矢量
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- C++将文本文件中的数据读取到结构数组中
- 在指针的帮助下,文本文件中单词的频率
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将值从二维数组输出到文本文件
- 如何在c++中从文本文件中逐行读取整数
- 以原子方式将彩色文本写入 Windows 中的控制台
- Xcode Windows.h并显示彩色文本
- CRichEditCtrl 附加彩色文本
- Windows 命令提示符中的彩色文本在一行中
- 如何在Windows上使用代码块在C++中输出彩色文本
- 如何使用ANSI转义码在C和c++中输出彩色文本
- 在透明窗口上书写的文本周围的透明颜色键的彩色边框