1

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

  • 3
    Unfortunately there's no completely cross platform solution in standard C++. We'd need to know what platform you're on. –  Jun 16 '20 at 20:51
  • 2
    my bad forgot to include i’m on Windows – Aiden Rossi Jun 16 '20 at 20:54
  • Does this answer your question? [C++ Win32 Console Color](https://stackoverflow.com/questions/17125440/c-win32-console-color) – Yunnosch Jun 16 '20 at 20:56
  • 1
    Most of the possible answers won't work unless you enable support, see https://stackoverflow.com/q/16755142/103167 – Ben Voigt Jun 16 '20 at 20:59

1 Answers1

0

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684