tags:

views:

105

answers:

5

How to use string index in c++ arrays(like php)?

+2  A: 

The closest thing is probably a std::map.

Check out the wikipedia page for details.

FigBug
+1  A: 

You need to use something like std::map to have an object with behavior similar to associative array.

Dmitriy Matveev
+7  A: 

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.

sth
+3  A: 

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

CrazyJugglerDrummer
A: 

This functionality called Map in general. If you already use Boost you can use their Maps, if not you must think twice :) Ok, if not Dimtry right - std::map is what you need.

Alexey Sviridov