How to return a value of variable 's name as a string when I put a string likes variable 's name :
1 2 3 4 5
|
int LIFE = 4;
float MANA = 100;
bool MARRIED = true;
cout << " Input Name: ";
cout << .... ;
|
When I put "LIFE" => print "4" in screen
"MANA" => print "100"
"MARRIED" => print on screen "true"
...
Can I use macro in this case?
If not,please don't use any ways such as :
if (!strcmp(input,"LIFE")) printf(" %d",LIFE);
Sorry about my English
Reply ASAP ,thank you !!
Last edited on
yes @Moschops you say the bestest way ;) and i really agree with you. the best and easiest way is map stl container
But you can't get an arbitrary variable's value from its variable name using C++
The variable name is thrown away by the compiler.
(Debuggers know the names as they use symbol lookup, from variable address to name, which prob. uses a map!)
Last edited on
Thank 4 all,mapping value key and mapped key is the best ways to solve this problem