STL Map multiple Key-Value Pairs
Hi*!
I am working on a DB application. I want to put the retured data into an STL map. I know how to use a map but that has been with one key-value pair.
Something like
PHP Code:
typedef std::map<std::string, std::string> SomeMap;
etc etc
Now i want to create map that has for every column a key and respective value from the row . So I'll have for every row a new map & for the whole table an array of maps.
How to do it????
Or is there a better way to store data in a diff format???
Secondly whats the difference b/w the map and hash_map????
Any Comments & suggest are most Welcome!Thanks for your time,
Regards,
Usman.
Re: STL Map multiple Key-Value Pairs
Quote:
Originally posted by usman999_1
Hi*!
I am working on a DB application. I want to put the retured data into an STL map. I know how to use a map but that has been with one key-value pair.
Something like
PHP Code:
typedef std::map<std::string, std::string> SomeMap;
etc etc
Now i want to create map that has for every
column a key and respective value from the
row . So I'll have for every row a new map & for the whole table an array of maps.
How to do it????
Or is there a better way to store data in a diff format???
I don't know what you really want; it's difficult for me to
understand, but I think you're saying you want the map's value
to be another map? If so, you can do whatever you want with
the STL:
typedef std::map<someKeyType, someDataType> Value;
typedef std::map<anotherKeyType, Value> Column;
typedef std::vector<Column> Table;
Quote:
Secondly whats the difference b/w the map and hash_map????
I'd recommend that you get a good book that tells you about the
STL. hash_map isn't in the C++ standard like map so using it
will not be 100% portable. I'm not going to explain it, though; I
will leave that to the book you choose to read. The two books
that have helped me the most with the STL are:
Effective STL by Scott Meyers
The C++ Standard Library by Nicolai M Josuttis
You should also have
The C++ Programming Language by Bjarne Stroustrup
--Paul