C++字符串值作为另一个字符串名称

Bab*_*ker 0 c++

如何在C++中将vartiables值转换为其他名称?就像在这个PHP片段.

$string = 'testVar';

${$string} = 'test';

echo $testVar; // test
Run Code Online (Sandbox Code Playgroud)

Bkl*_*lyn 6

如何使用地图?

#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;
Run Code Online (Sandbox Code Playgroud)