I have a std::set<std::string>
and I want to know the exact position of the element in the set after the insertion.
I tried with std::distance
but without any luck:
#include <iostream>
#include <string>
#include <set>
#include <iterator>
using namespace std;
int main (int argc, char const *argv[])
{
string array[] = { "zero", "one", "one", "zero", "two", "three", "zero" };
set<string> numbers;
for(size_t i = 0; i < 7; ++i)
{
int dist = distance(numbers.begin(), numbers.insert(array[i]).first);
cout << array[i] << "\t" << dist << endl;
}
return 0;
}
outputs:
zero 0
one 0
one 0
zero 1
two 1
three 1
zero 3
Instead, I was expecting this:
zero 0
one 1
one 1
zero 0
two 2
three 3
zero 0
Any ideas?