How to use string indexes in c++ arrays (like php)?
You could use std::map
to get an associative container in which you can lookup values by a string index. A map like std::map<std::string, int>
would associate integer values with std::string
lookup keys.
They're called associative arrays (or dictionaries) and the allow you to use any type you want as a key, instead of just integers. They're natively supported in PHP, in C++ you should probably use std::map unless you're in .net, which has its own dictionary class
The closest thing is probably a std::map.
Check out the wikipedia page for details.