Home | News | Documentation | Download

Declaring Variables on the runtime


#1

Hello
I want to change the variable names dynamically, on the runtime. I want to create five arrays whose name would be determined on the runtime. How can we do?
Thank you


#2

You cannot change variable names at runtime. Use a std::map instead.


#3

How to use ?
Could you please guide?


#4
map<string, vector<int>> m;

m["hello"].push_back(1);
m["worlxd"].push_back(2);

// now renaming worlxd to world (overwriting previous "world"):
auto it = m.find("worlxd");
m["world"] = std::move(it->second);
m.erase(it);


#5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.