Sto cercando di ottenere l'indice di un elemento in un vettore di strings, di usarlo come indice in un altro vettore di inttipo, è possibile?
Esempio:
vector <string> Names;
vector <int> Numbers;
...
// condition to check whether the name exists or not
if((find(Names.begin(), Names.end(), old_name_)) != Names.end())
{ // if yes
cout <<"Enter the new name."<< endl;
cin >> name;
replace(Names.begin(), Names.end(), old_name_, name);
}
Ora voglio ottenere la posizione di old_namenel Namesvettore, per usarla nell'accesso a determinati elementi nel Numbersvettore. Così posso dire:
Numbers[position] = 3 ; // or whatever value assigned here.
Ho provato a usare:
vector <string> :: const_iterator pos;
pos = (find(Names.begin(), Names.end(), old_name_))
Numbers[pos] = 3;
ma ovviamente questo non funziona poiché posè di tipo stringa!