How to use a string as a variable name in C++? [duplicate]
Solution 1:
You can't in C++.
One thing you can do is use a form of std::map<std::string, std::vector>
to store name to vector map.
Solution 2:
You don't.
Variable names are a compile-time construct. The contents of a string are a run-time concept (string literals are slightly different, but those won't work either). Unless you write a specific mapping layer (which maps a string name to some object), you cannot just use a string as a variable name.
Or a type name for that matter.