enum to string

Pages: 12
@Jackson Marie
if you want that you're advices are more solid check if they're ok. The best way you can do that is to create a test project. Compile and if necessary debug.

if you had done that you'd know that the code provide by Darkmaster is ok and his problem must be beside that (linking)

I know it's time consuming, but it pays...
You may want to consider writing a general function that returns a string from a COLOR, then call that function from the ostream function. The reason for this would be so that you can call the COLOR->string function anywhere you want instead of having to write a new function if you want to do the conversion somewhere other than an ostream. Like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
std::string COLOR_to_string(const COLOR &color)
{
	switch(color)
	{
		case RED: return "red";
		case YELLOW: return "yellow";
		case GREEN: return "green";
		case CYAN: return "cyan";
		case BLUE: return "blue";
		case VIOLET: return "violet";
		default: return "";
	}
}

std::ostream &operator << (std::ostream &os, COLOR &color)
{
	os << COLOR_to_string(color);
	return os;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 12