By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

iDENTIFIER CONVERSION INTO STRING

P: 1
I want to know that how we can get identifier of a variable as string at run time.
this will seem something like this:

int empno=20;
char *id=identifier_to_string(emp);
cout<<id; =>it should print emp;

or

int empno=20;
char *id="emp";
cout<<string_as_identifier(id); => it should print 20;

I will be gratefull to you for help.
Feb 19 '07 #1
Share this Question
Share on Google+
2 Replies


100+
P: 1,646
Hi. Perhaps it would be more useful if you were to explain what it is that you want to achieve without referring to strings etc. What you want this part of your app to do. because cout << empno; will also output 20.
Thanks
Feb 19 '07 #2

AdrianH
Expert 100+
P: 1,251
What will has said is true, you can store the info as integers.

C++ doesn't intrinsically store the strings of enums. Though there have been times I wish it did. I have done things to work around it, but I can tell you it ainít pretty. :) It requires the use of the pre-processor directives. If you really want this, I can post it, but be advised, what I am talking about is very advanced and if you were to use it in a course without being able to explain what the hell you are doing, you will get an automatic zero.

That said, it is pretty neat stuff. ;)


Adrian
Feb 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.