I’m trying to change the color of my text in c++ i have scavengend the internet at this point. Could anyone help me I tried using “#include ” but that still does not work.
I swear i always forget to include this but i’m on Windows
I’m trying to change the color of my text in c++ i have scavengend the internet at this point. Could anyone help me I tried using “#include ” but that still does not work.
I swear i always forget to include this but i’m on Windows
I can't offer you a proper C++'ish solution, but - C libraries work well with C++, and ncurses can be your friend. 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); or use find_package(Curses REQUIRED)
in your CMakeLists.txt
, if you use CMake.