Access variable value using string representing variable's name
Posted
by Paul Ridgway
on Stack Overflow
See other posts from Stack Overflow
or by Paul Ridgway
Published on 2010-05-26T08:56:52Z
Indexed on
2010/05/26
9:51 UTC
Read the original article
Hit count: 176
Hello everyone,
If the title was not clear, I will try to clarify what I am asking:
Imagine I have a variable called counter, I know I can see its current value by doing something like:
std::cout << counter << std::endl;
However, assume I have lots of variables and I don't know which I'm going to want to look at until runtime.
Does anyone know a way I can fetch the value of a variable by using its name, for example:
std::cout << valueOf("counter") << std::endl;
I feel being able to do this might make debugging large complex projects easier.
Thanks in advance for your time.
© Stack Overflow or respective owner