I am trying to retrieve the value that is stored in a particular spot in a mulitset, but all I'm unable to find out how to do that anywhere online. This is also my first time using multisets in C++.
The multiset that I want to get the value from is the numerator, and it's declared in the header file that I attached to my program. Below is what I have tried.
// This method will swap the numerator and denominator values
void Fraction::Invert() {
int tmp = 0;
for (int i = 0; i < (int)numerator.size(); i++) {
// I want the value stored in the multiset (numerator) at i
tmp = numerator.find(i);
}
}
Many methods exist so you can retrieve a value from a multiset.
First:
You can use an iterator. Something like below:
In the your example, it is like below:
Second:
You can use the range for style:
And in the your example, it is like below: