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 uselower_bound()
, passingstd::pair
minimum valueint
portion, , string you're search for, , seelower_bound()
digs up.perhaps reconsider decision use
std::set
whatever purpose you're using. perhapsstd::set
, containingstd::pair
, isn't appropriate container requirements.
Comments
Post a Comment