-
January 11th, 2004, 09:44 PM
#1
STL vectors vs. maps
I need a collection which will associate a string with an integer. The strings will be added numerically and so the number associated to the first string added will be 0, the second 1, etc. I was thinking I would use a vector, but the problem is that I then want to be able to search the collection for the string and find the integer related to it. A vector does not seem to have an existing search algorithm (am I wrong?). I could write one myself, but I was hoping there was another way.
I also looked at using a map, but I am finding the interface to a map to be needlessly complex. The example I have looked at shows:
theMap.insert(INT2STRING::value_type(0,"Zero"));
where I would rather just use:
theMap.insert(0,"Zero");
and searching the map involves iterators, and all sorts of other needless garbage when I just want to have a method like:
int find(string searchString);
So do I need to write a custom class or method, or is there something I am not seeing.
thanks,
eggman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|