我正在尝试用c ++更改文本的颜色,目前我已经在Internet上进行了搜索。任何人都可以帮我,我尝试使用“ #include”,但这仍然行不通。
我发誓我总是会忘记添加它,但是我在Windows上
答案 0 :(得分:0)
我无法为您提供适当的C ++解决方案,但是-C库可以很好地与C ++配合使用,ncurses可以成为您的朋友。引用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? :-(
}
记住要与-lcurses
链接(在类Unix的机器上);或如果您使用CMake,请在find_package(Curses REQUIRED)
中使用CMakeLists.txt
。