void textcolor (string f, int fi, string b, int bi) {
switch (f){
case"Green": f="FOREGROUND_GREEN"; break;
case"Blue": f="FOREGROUND_BLUE"; break;
case"Red": f="FOREGROUND_RED"; break;
case"Yellow": f="FOREGROUND_RED| FOREGROUND_GREEN"; break;
case"Cyan": f="FOREGROUND_GREEN | FOREGROUND_BLUE"; break;
case"Purple": f="FOREGROUND_BLUE | FOREGROUND_RED"; break;
case"White": f="FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN"; break;
default: cout << "FOREGROUND COLOR NOT SPECIFIED" << endl;};
if (fi==1) fi="| FOREGROUND_INTENSITY"else fi=0;
switch (b){
case"Green": b="BACKGROUND_GREEN"; break;
case"Blue": b="BACKGROUND_BLUE"; break;
case"Red": b="BACKGROUND_RED"; break;
case"Yellow": b="BACKGROUND_RED | BACKGROUND_GREEN"; break;
case"Cyan": b="BACKGROUND_GREEN | BACKGROUND_BLUE"; break;
case"Purple": b="BACKGROUND_BLUE | BACKGROUND_RED"; break;
case"White": b="BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN"; break;
default: cout << "BACKGROUND COLOR NOT SPECIFIED" << endl; };
if (bi==1) bi="| BACKGROUND_INTENSITY"; else bi=0;
//To be honest, I'm not really sure whether the colors (ie FOREGROUND_RED) should be in quotes or not, since they are used as parameters.
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), f fi);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), b bi);}
1>(3) : error C2450: switch expression of type 'std::string' is illegal
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(4) : error C2051: case expression not constant
1>(5) : error C2051: case expression not constant
1>(6) : error C2051: case expression not constant
1>(7) : error C2051: case expression not constant
1>(8) : error C2051: case expression not constant
1>(9) : error C2051: case expression not constant
1>(10) : error C2051: case expression not constant
Duh, of course it's not going to be constant or you wouldn't need a switch case statement.
1>(11) : warning C4065: switch statement contains 'default' but no 'case' labels
Umm.. I'm pretty sure it does. See lines 4-10
1>(12) : error C2440: '=' : cannot convert from 'const char [23]' to 'int'
1> There is no context in which this conversion is possible
I'm not asking you to. You should be converting from string to string.
1>(14) : error C2450: switch expression of type 'std::string' is illegal
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
You tell me it's wrong when I use char var[#] too, what am I supposed to use?
1>(15) : error C2051: case expression not constant
1>(16) : error C2051: case expression not constant
1>(17) : error C2051: case expression not constant
1>(18) : error C2051: case expression not constant
1>(19) : error C2051: case expression not constant
1>(20) : error C2051: case expression not constant
1>(21) : error C2051: case expression not constant
1>(22) : warning C4065: switch statement contains 'default' but no 'case' labels
1>(23) : error C2440: '=' : cannot convert from 'const char [23]' to 'int'
1> There is no context in which this conversion is possible
1>(25) : error C2146: syntax error : missing ')' before identifier 'fi'
1>(25) : error C2664: 'SetConsoleTextAttribute' : cannot convert parameter 2 from 'std::string' to 'WORD'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(25) : error C2059: syntax error : ')'
1>(26) : error C2146: syntax error : missing ')' before identifier 'bi'
1>(26) : error C2664: 'SetConsoleTextAttribute' : cannot convert parameter 2 from 'std::string' to 'WORD'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>(26) : error C2059: syntax error : ')'
you can't use the switch statement for strings, it's only for integral type.
The SetConsoleTextAttribute takes a WORD (unsignedshort) as argument, not a string