【发布时间】:2011-12-08 08:50:07
【问题描述】:
我想写一些类似的东西
cout << "this text is not colorized\n";
setForeground(Color::Red);
cout << "this text shows as red\n";
setForeground(Color::Blue);
cout << "this text shows as blue\n";
对于在 Windows 7 下运行的 C++ 控制台程序。我已阅读可以从 cmd.exe 的设置或通过调用 system() 更改全局前景和背景 - 但有什么方法可以在字符级别更改内容可以编码成程序吗?起初我以为是“ANSI 序列”,但它们似乎早已在 Windows 领域消失了。
【问题讨论】:
-
使用 SetConsoleTextAttribute()。
标签: c++ windows console-application windows-console