How do I get the first 5 elements of a map?
toolbox03 -3 Light Poster
Recommended Answers
Jump to Posttemplate<typename T, typename U> void print_first_five( map<T,U> m ) { for (int i = 0; i < (m.size() >= 5) ? 5 : m.size(); i++) cout << m[i].second; }
Hope this helps.
Jump to Posttemplate<typename T, typename U> void print_first_five( map<T,U> m ) { for (int i = 0; i < (m.size() >= 5) ? 5 : m.size(); i++) cout << m[i].second; }
Hope this helps.
This is wrong, by the way. "m" looks up "i" as a key in the map. …
All 5 Replies
Duoas 1,025 Postaholic Featured Poster
toolbox03 -3 Light Poster
Duoas 1,025 Postaholic Featured Poster
bugmenot 25 Posting Whiz in Training
Duoas 1,025 Postaholic Featured Poster
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.