I'm working on a code and I'm using ncurses and stringstreams (C++).
I want to print (only) the number in red if it's negative and in green if it's positive.
By the structure of the program, I use a single stringstream for the entire output. So if I change the color with:
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
attron(COLOR_PAIR(1));
It colors all the output (I just want the numbers to be colored). I've also tried with ANSI code, but it doesn't work with ncurses.
My code is something like this:
stringstream_var.clear();
stringstream_var.str(std::string());
if (num1 < 0){
//I just want to print num1 in red
stringstream_var << "Number 1: " << num1 << std::endl;
}else{
//I just want to print num1 in green
stringstream_var << "Number 1: " << num1 << std::endl;
}
How could I achive this?
Is it possible?