Okay, maybe this is a dumb question, but here it goes: Consider the
following code:
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
Now, we all know that enums positions are looked at as integers, how would
one go about displaying say "Mon" rather than "1"? For example consider
some more code:
#include <iostream>
#include "stdlib.h"
using namespace std;
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
int main()
{
int iChoice;
cout << "Enter a number representing it's corresponding day of the week:
"; cin >> iChoice;
cout << "Your day is " << // what would I type here to access the
corresponding place in day_of_week?
system("PAUSE");
return 0;
}
Thanks for your help
--
"Black holes are where God divided by zero." -Steven Wright 3 8949
"Aaron Toponce" <to*******@yahoo.com> wrote in message
news:EdtKa.19445$R73.3886@sccrnsc04 Okay, maybe this is a dumb question, but here it goes: Consider the following code:
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
Now, we all know that enums positions are looked at as integers, how would one go about displaying say "Mon" rather than "1"? For example consider some more code: #include <iostream> #include "stdlib.h" using namespace std;
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
int main() { int iChoice;
cout << "Enter a number representing it's corresponding day of the week: "; cin >> iChoice; cout << "Your day is " << // what would I type here to access the corresponding place in day_of_week?
cout << "Your day is " << days[iChoice-1];
system("PAUSE"); return 0; }
Thanks for your help -- "Black holes are where God divided by zero." -Steven Wright
You are assuming agreement that Monday is the first day of the week, by the
way (some people would say that Sunday is).
--
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)
On Thu, 26 Jun 2003 02:52:21 GMT, Aaron Toponce <to*******@yahoo.com> wrote: Okay, maybe this is a dumb question, but here it goes: Consider the following code:
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
Now, we all know that enums positions are looked at as integers, how would one go about displaying say "Mon" rather than "1"? For example consider some more code:
You wouldn't.
Enums don't provide strings. Use an array of strings or something instead.
--
Sam Holden
"Aaron Toponce" <to*******@yahoo.com> wrote in message news:<EdtKa.19445$R73.3886@sccrnsc04>... Okay, maybe this is a dumb question, but here it goes: Consider the following code:
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
Now, we all know that enums positions are looked at as integers, how would one go about displaying say "Mon" rather than "1"? For example consider some more code: #include <iostream> #include "stdlib.h" using namespace std;
enum day_of_week {Mon = 1, Tue, Wed, Thu, Fri, Sat, Sun};
int main() { int iChoice;
cout << "Enter a number representing it's corresponding day of the week: "; cin >> iChoice; cout << "Your day is " << // what would I type here to access the corresponding place in day_of_week?
system("PAUSE"); return 0; }
It exists a solution that you'll obtain searching with keywords
"C++ enum to string" into Google groups (sorry, I don't know how to have
the URL of the answer), a posting on june 16 2003.
It proposes you writing someting like:
//##markup##"enum DAY_OF_WEEK"
//##data##
//Mon
//Tue
//Wef
//Thu
//Fri
//Sat
//Sun
//##data##
and a code generator easy-to-use writes both the enum definition and the
function 'std::string DAY_OF_WEEKToString(DAY_OF_WEEK e)' for you in your
code.
Note that a small improvement should be brought to take into account the
assignment of a value to the enum.
-- Cedric This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: SpaceCowboy |
last post by:
I recently got into a discussion with a co-worker about using enums across a
dll interface. He wanted to use chars instead, argueing that depending on
compiler settings the size of an enum could...
|
by: Faisal |
last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
|
by: Mark A. Gibbs |
last post by:
i have been toying with the idea of making my enums smarter - ie, more
in line with the rest of the language. i haven't tested it yet, but what
i came up with is a template like this:
template...
|
by: SpotNet |
last post by:
Hello CSharpies,
Can Enums in C# be UInt32 Types, and not just Int32 Types. I have a lot of
constant declarations that are UInt32 that I want to put in Enums to ease
the use of Intellisence. I...
|
by: Martin Pritchard |
last post by:
Hi,
I'm working on a project that historically contains around 40 enums. In the
database various fields refer to the int values of these enums, but of
course ref integrity is not enofrced and...
| |
by: Faisal |
last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
|
by: Simon Elliott |
last post by:
I have some legacy C++ code which requires some enums to be 1 or 2
bytes in size.
I'd ideally like to be able to specify that a few carefully selected
enums are a particular size.
By default,...
|
by: Marc Gravell |
last post by:
This one stumped me while refactoring some code to use generics...
Suppose I declare an enum MyEnum {...}
Is there a good reason why MyEnum doesn't implement IEquatable<MyEnum> ?
Of course,...
|
by: Jon Slaughter |
last post by:
is there a simple way to "step" through enums? I have a button that I want
to click and have it "cycle" through a set of states defined by enums but
the only way I can think of doing this...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |