Enumerated type variable

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
	enum numSet {zero, one, two, three};
	numSet numA = one;
	cout << "numA = " << (numA) << endl;
}

The program output is
numA = 1
, but how can I have an output like
numA = one
Just for laughs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <map>

using namespace std;

int main()
{
	enum numSet {zero, one, two, three};
	
	map<numSet, string> names;
	names[zero] = "zero";
	names[one] = "one";
	names[two] = "two";
	names[three] = "three";
	
	numSet numA = one;
	cout << "numA = " << names[numA] << endl;
}
Enums are meant to be integral constants. If you just want a useful collection of strings try creating a class with a container and various helper methods like Add, Delete, Find, Print, etc.
Topic archived. No new replies allowed.