Hey guys,

I have some code set up to iterate through a nested map. It current works as expected, iterating through all values in the first key, and then the second key.

My question is, is there any way to display one value from each key?

For example, if key 0 contains a vector containing a b c d and key 1 contains a vector containing 1 2 3 4, would there be any way to output a 1 b 2 c 3 d 4, instead of a b c d 1 2 3 4?

I hope the question is clear.

Thanks!

This may give you a start?

const string s = "abcd";
const string n = "1234";

for( size_t i = 0; i < s.size(); ++ i )
{
    cout << s[i] << n[i];
}

For example, if key 0 contains a vector containing a b c d and key 1 contains a vector containing 1 2 3 4, would there be any way to output a 1 b 2 c 3 d 4, instead of a b c d 1 2 3 4?

std::map doesn't readily support that in an elegant manner. Obviously you could repeatedly iterate through all of the keys, maintain an index to the value, and output the element at that index. But this seems like more of a band-aid born from the wrong data structure choice.

So let's take a step back and figure out exactly what the purpose of this map is. Can you clarify?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.