String as Variable Name

Is there any way to use the data from a string variable as the name for another variable?
Look into std::map.
How do I do that in Visual Studio? Can't you just tell me the syntax to use if I use the std namespace?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <map>
#include <string>

int main()
{
  // the "key" is a std::string
  // the "value" is an int
  std::map<std::string,int> myvars;

  std::string myvarname = "whatever";

  myvars[myvarname] = 5;

  std::cout << myvars[myvarname];
}
How exactly does that example then let me use the variable whatever? Does whatever = 5 now or what?
myvars["whatever"] = 5;. Line 13 does that only with the name stored in a string.
Topic archived. No new replies allowed.