问题描述
哪个 C++ 函数会更改文本或背景颜色(MS Visual Studio)?比如cout<<"This text";如何让"This text"变成红色.
Which C++ function changes text or background color (MS Visual studio)? For example cout<<"This text"; how to make "This text" red color.
推荐答案
颜色不是 C++ 的东西,而是 终端 的属性.如果您的终端使用 ANSI(例如,任何 Linux 终端,或 DOS 或 Windows NT,如果您将 DEVICE=C:DOSansi.sys 添加到您的 config.sys,或以后的Windows如果你用cmd.exe/kansicon调用shell,那么你可以试试下面的噱头:
Colour isn't a C++ thing, but a property of your terminal. If your terminal speaks ANSI (e.g. any Linux terminal, or DOS or Windows NT if you add DEVICE=C:DOSansi.sys to your config.sys, or later Windows if you call the shell with cmd.exe /kansicon), then you can try the following gimmick:
#define ANSI_COLOR_RED "x1b[31m"
#define ANSI_COLOR_GREEN "x1b[32m"
#define ANSI_COLOR_YELLOW "x1b[33m"
#define ANSI_COLOR_BLUE "x1b[34m"
#define ANSI_COLOR_MAGENTA "x1b[35m"
#define ANSI_COLOR_CYAN "x1b[36m"
#define ANSI_COLOR_BRIGHT "x1b[1m"
#define ANSI_COLOR_RESET "x1b[0m"
std::cout << ANSI_COLOR_RED "Hello World
" ANSI_COLOR_RESET;
维基百科有一个ANSI 转义序列列表.
这篇关于如何更改 Windows 控制台应用程序中的文本或背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)