Associative containers are ordered and implemented as binary search trees. They have a find method (O(log(n))) which returns an iterator.

Example with set

#include <iostream>
#include <set>

int main()
{
    std::set<int> mySet;
    mySet.insert(4);
    mySet.insert(2);
    mySet.insert(6);
    mySet.insert(1);

    for (auto& i : mySet) {
        std::cout << i << std::endl;
    }

    std::set<int>::iterator find = mySet.find(2);
    if (find != mySet.end()) {
        std::cout << "Element found" << std::endl;
        long idx = std::distance(mySet.begin(), find);
        std::cout << "Found element at index " << idx << std::endl;
    }

    std::pair<std::set<int>::iterator, bool> ret = mySet.insert(6);
    // ret.second is false if the element already existed
    // the returned iterator then points to the existing element
    // if insertion was successful it points to newly inserted element
    if (ret.second == false) {
        std::cout << "Element " << *(ret.first) << " already in set." << std::endl;
    }
}

Working with maps

#include <iostream>
#include <map>

void printItems(const std::map<std::string, int>& map) {
    // map["Apple"] fails if map is const
    std::cout << map.at("Apple") << std::endl;
    auto itr = map.find("Apple");
    std::cout << itr->second << std::endl;

}

int main()
{
    std::map<std::string, int> item2price;
    // no modification via insert
    item2price.insert(std::make_pair("Apple", 3));
    item2price.insert(std::make_pair("Orange", 1));
    for (const std::pair<const std::string, int>& entry : item2price) {
        std::cout << "Item: " << entry.first << " price: " << entry.second << std::endl;
    }
    // modification and insertion possible
    item2price["Banana"] = 2;
    item2price["Apple"] = 5;
    for (auto itr = item2price.begin(); itr != item2price.end(); ++itr) {
        std::cout << (*itr).first << " " << itr->second << std::endl;
    }
    std::cout << item2price.at("Apple") << std::endl;
    // indexing is not possible if map is const! [] implies write operation on container
    std::cout << item2price["Apple"] << std::endl;
    printItems(item2price);

}