C++ creating a change console colors function -


cout << "picks colors..." << endl << "0 = black\t 1 = blue\t 2 = pea green\t 3 = teal\t 4 = red" << endl; cout << "5 = purple\t 6 = green/brown\t 7 = light grey\t 8 = gark grey" << endl; cout << "9 = lisghter brighter blue\t = lime green\t b = light blue/aqua-ish\t c = red/orange" << endl; cout << "d = pink/rose\t e = yellow" << endl; char bg; char fg; cout << "pick foreground:\t"; cin >> fg; cout << "pick background:\t"; cin >> bg; string colors; colors = "0x",bg,fg; setconsoletextattribute( hstdout, colors ); 

this function allow user input change console colors. know fact works windows, i'm not sure on linux machine. unfortunately don't know how compose string colors including characters in string goes console attribute function. using method error...

error: cannot convert 'std::string' 'word' argument '2' 'bool setconsoletextattribute(void*, word)'

any ideas? better ways can change colors? know of windows system calls, thought may or may not work on linux. possibly make 2 different calls , 1 linux, sounds complicated , wouldn't know how make program tell difference.

as noted, function takes word value. in essence, there defined constants of red, green, , blue values background , foreground colors can mixed create other colors. example piece of code site:

http://www.adrianxw.dk/softwaresite/consoles/consoles4.html

#include <windows.h> #include <iostream> using namespace std;  int main() {   handle hout;    hout = getstdhandle(std_output_handle);    setconsoletextattribute(hout,                         background_green |                         background_red |                         foreground_green |                          foreground_blue |                         foreground_intensity);   cout << "intense cyan on yellow background." << endl;    return 0; } 

the site lists other combinations can used.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -