So in C#, I have something similar to the following:
Dictionary<string, List<string>>
What's the most efficient way to do that in C++? I know c++ has 'map' and 'list' but I'm still in the pseudocode phase of writing this function, so I was wondering if something like this is even possible in C++. If so, how's the best way to make that equivalent data structure?
Thanks
so I was wondering if something like this is even possible in C++
Yes. The STL features are variety of different containers: http://www.cplusplus.com/reference/stl/.
If so, how's the best way to make that equivalent data structure?
That depends on your requirements. For example std::vector
vs std::list
(see here for further information)
For a simple case I would just suggest you to use something like this:
#include <vector>
#include <map>
#include <string>
int main()
{
std::map<std::string, std::vector<std::string>> map_of_strings;
map_of_strings["a"] = { "1", "2", "3" };
map_of_strings["b"] = { "4", "5", "6" };
map_of_strings["c"] = { "7", "8", "9" };
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With