0

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!

Edited by collin_ola

3
Contributors
2
Replies
27
Views
2 Years
Discussion Span
Last Post by deceptikon
0

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];
}

Edited by David W

2

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.