In normal C/C++ conditions, variable names only exist for their given scope during compilation, they are essentially human-readable mnemonics for referencing specific memory locations/registers.
C/C++ has no-to-minimal reflection capabilities, so there is no built-in way, at runtime, to reference a variable by name or look up the name of a variable by it's location/value.
To solve the problem you are describing, there are several simple options:
int value;
if (TakeFrom == "a") {
value = a;
} else if (TakeFrom == "b") {
value = b;
} ...
or
switch (TakeFrom[0]) {
case 'a':
value = a;
break;
case 'b':
value = b;
break;
}
or you could use a lookup table
int a = 1, b = 2, c = 3;
struct Lookup {
int& m_variable;
const char* m_name;
};
static const size_t NumLookups = 3;
Lookup lookups[NumLookups] = { { a, "a" }, { b, "b" }, { c, "c" } };
for (size_t i = 0; i < NumLookups; ++i) {
if (TakeFrom == lookups[i].m_name)
value = lookups[i].m_variable;
}
std::mapto map strings (variable names) to ints.