How to access elements of a pair set in C++ -


i have set. of form set<pair<string,int> > stockset want find if above set has entry given string first element. find value of 2nd part of pair, int given first element of pair string.

i know how map , single element set. unable figure out how this, need syntax.

you can't figure out because can't this.

the elements in set "complete" elements. because see std::pair in there, , think set contains 2 elements, doesn't mean is. set contains std::pair, single, complete, element.

if have std::pair, somewhere, can search set see if there's equivalent pair in there. if have half of object set contains, can't it.

the options see here are:

  • iterate on set manually, until or not find you're looking for.

  • if there's minimum int value expect in there, can use lower_bound(), passing std::pair minimum value int portion, , string you're search for, , see lower_bound() digs up.

  • perhaps reconsider decision use std::set whatever purpose you're using. perhaps std::set, containing std::pair, isn't appropriate container requirements.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -