C ++ string value as another string name
How about using the card?
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, string> hitters;
hitters["leadoff"] = "Jeter";
hitters["second"] = "Damon";
hitters["third"] = "Teixiera";
hitters["cleanup"] = "Matsui";
string hitter = "cleanup";
cout << hitters[hitter] << endl;
a source to share
I don't know PHP, but I don't think you can do this in C ++. A variable name has no runtime representation in a compiled C ++ program, so there is no way to load its name at runtime.
This is similar to what you can only do in a scripting language where the source code is in memory, or at least some representation of a syntax tree.
a source to share
This is not something you can do in C ++. When you compile C ++ code, information about which name functions and variables are lost (technically, they can be stored in symbol tables, but they are for debugging purposes only). To accomplish something like this, you would need to use a map or some other similar data structure that looks more like a PHP array.
a source to share
It looks like you can use pointers:
string testVar;
string *str = &testVar;
*str = "test";
cout << testVar << endl; // test
After compilation, the C ++ compiler discards information similar to the original variable names, so you need to use lower-level constructs to do the same types.
a source to share
If you compile your program with the symbol table, you can use "readelf -s yourexecutable" (linux) to get the symbol table. Then grep on the output with the variable name and on the output get the address with the "cut" command.
readelf -s a.out | grep ' var$' | tr -s ' '| cut -d' ' -f3
a source to share