enum qustion

if i defined enum like this day{sun,mon,tue,wed},
how can i create a variable from type day and make the user intialize it?

There is no built-in enum/string conversion. If you want the user to type the name of the day and then set the enum to the correct value you will have to write the code for each case yourself.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
enum day {sun,mon,tue,wed};

std::string dayString;
day d;

std::cin >> dayString;

if (dayString == "sunday")
{
	d = sun;
}
else if (dayString == "monday")
{
	d = mon;
}
else if (dayString == "tuesday")
{
	d = tue;
}
else if (dayString == "wednsday")
{
	d = wed;
}
else 
{
	// Invalid date !!! What to do?
}
Topic archived. No new replies allowed.