I need to use STL C++ map to store key value pairs.
I need to store more than one data information in stl map.
e.g
Need to store DataType,Data and its behavior as(in param/outparam) all in string format.
But map always use key value pair
so if I
store it like
std::map<map<"int","50",>"behavior">.
But always it sorts the the data on basis of keys which I dont want. If I use like ..
pair<string, pair<string,string> >;
pair<string, pair<string,string>>("int",("100","in"));
This prompts compile time error!
error C2664: ‘std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)’ : cannot convert parameter 1 from ‘const char *’ to ‘const std::pair<_Ty1,_Ty2> &’
What should be the exact solution of the above problem?
Regards
If you don’t want ordering, don’t use ordered containers like map or set. You could achieve what you’re looking for using a class and a vector. The sorted nature of std::map is what makes it efficient to lookup by key. If you want/need unsorted and more hash like behavior for lookups, look at Boost unordered containers. Note that this doesn’t guarantee the order in is going to be the order out. I’m assuming you want to preserve the order of the types your putting in the container, the example below will do that.