简体   繁体   English

在 C++ 控制台中更改文本颜色

[英]Changing Color of Text In C++ Console

I'm trying to change the color of my text in c++ i have scavengend the internet at this point.我正在尝试更改 c++ 中文本的颜色,此时我已经清除了互联网。 Could anyone help me I tried using “#include ” but that still does not work.谁能帮助我我尝试使用“#include”,但这仍然不起作用。

I swear i always forget to include this but i'm on Windows我发誓我总是忘记包括这个,但我在 Windows

I can't offer you a proper C++'ish solution, but - C libraries work well with C++, and ncurses can be your friend.我无法为您提供适当的 C++'ish 解决方案,但是 - C 库与 C++ 配合得很好, ncurses可以成为您的朋友。 Quoting from this answer :引用这个答案

#include <curses.h>

int main() {
    initscr();
    start_color();
    init_pair(1, COLOR_BLACK, COLOR_RED);
    attron(COLOR_PAIR(1));
    printw("This should be printed in black with a red background!\n");
    refresh();
    getch(); // so the program doesn't just quit immediately
    endwin(); // not very RAII, is it? :-(
}

Remember to link with -lcurses (on Unix-like machines);记得用-lcurses链接(在类 Unix 机器上); or use find_package(Curses REQUIRED) in your CMakeLists.txt , if you use CMake.或在CMakeLists.txt中使用find_package(Curses REQUIRED) ,如果您使用 CMake。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM