What I mean is, how do I use a char, which I can iterate, to identify a variable? So if:
int cheese = 1337;
string identifier = "cheese";
How do I use this string "identifier" to identify the variable cheese and return its value?
What I mean is, how do I use a char, which I can iterate, to identify a variable? So if:
int cheese = 1337;
string identifier = "cheese";
How do I use this string "identifier" to identify the variable cheese and return its value?
You don't.
Instead, you lay out your data differently, perhaps using a key-value store?
std::map<std::string, int> myData;
myData["cheese"] = 1337;
// ...
const std::string identifier = "cheese";
std::cout << myData[identifier] << '\n'; // 1337
Looks like you are looking for map
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<string, int> vars;
vars.insert(make_pair("cheese", 1337));
vars.insert(make_pair("geese", 1338));
if (vars.find("cheese") != vars.end())
cout << vars.at("cheese");
return 0;
}