hi..
i am facing a prob as shown below
it=find(value) and erase(it) erases both the values(in case of repeating values)... but how do i erase only one of the two values
thanks
Printable View
hi..
i am facing a prob as shown below
it=find(value) and erase(it) erases both the values(in case of repeating values)... but how do i erase only one of the two values
thanks
Does it?
Code:#include <set>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
multiset<int> s;
s.insert(2);
s.insert(3);
s.insert(1);
s.insert(2);
copy(s.begin(), s.end(), ostream_iterator<int>(cout, " ")); cout << '\n';
s.erase(s.find(2));
copy(s.begin(), s.end(), ostream_iterator<int>(cout, " ")); cout << '\n';
}
Quote:
1 2 2 3
1 2 3
no insertion is done in right way..(tat s the neccesity for multiset)
eg:
if i insert
1 2 2 3 3 4 5 6 7 8 8 9
its done
then my requirement is to delte the first occurence of 2
so i need to : find(2)
erase(it)
but when i erase
it is resulting in 1 3 3 4 5 6 7 8 8 9
but the expected outcome is
1 2 3 3 4 5 6 7 8 8 9
You may need to post your code because my code doesn't produce unexpected output.
Code:#include <set>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
int arr[] = {1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 8, 9};
multiset<int> s(arr, arr + sizeof(arr) / sizeof(arr[0]));
copy(s.begin(), s.end(), ostream_iterator<int>(cout, " ")); cout << '\n';
s.erase(s.find(2));
copy(s.begin(), s.end(), ostream_iterator<int>(cout, " ")); cout << '\n';
}
Quote:
1 2 2 3 3 4 5 6 7 8 8 9
1 2 3 3 4 5 6 7 8 8 9