creating array in c++ with string index
I am wondering if it is possible to create an array whose index are string.
For example I want to create a 2 dimensional array which looks like this: array["first"]["second"]=8; then I want to make a loop to verify each elements of my array. In PHP we have foreach, but I couldn't find the equivalent command in c++. |
Arrays are Evil!
what you want is a std::map<std::string, std::map<std::string, int> > (not the space in between the last two angle brackets, it is required). there is a for_each in the STL <functional> header. It's a bit complicated by itself, but with boost::lambda and/or boost::bind it's a win. |
Quote:
|
The enum keyword is used in C++ to create enumerated constants. STL maps are the way to go on this one.
|
All times are GMT -5. The time now is 05:55 PM. |