begin、end、first、last、size_type、iterator、const_iterator、value_type、reference、const_reference、cbegin、send、rbegin、rend。
這里begin和first指向的是同一個元素,是容器中的第一個元素。last指的是容器中的最后一個元素。而end指向的是last元素之后的位置,這個元素不存在實體。迭代器的范圍是[begin, end)??梢允褂?+運算符使得迭代器逼近end,使用–運算符使得迭代器逼近begin。cbegin和cend是begin和end的const版本,c版本的迭代器指向的位置不能修改。因此,如果不需要寫訪問時,應使用cbegin和cend。rbegin和rend是反向的begin和end使用++操作迭代器往左走,使用–操作迭代器往右走。需要注意的是forward_list不能使用–操作符,也不存在rbegin和rend。
當使用容器的size函數時,返回一個<容器>::size_type的值。這個值是無符號類型的,而且能放下任何string對象的大小。
可以使用<容器>::iterator和<容器>::const_iterator表示迭代器的類型。其中iterator能讀寫,而const_iterator只能讀。
需要元素類型,使用容器的value_type。如果需要元素類型的一個引用,可以使用reference或const_reference。三者的形式如下:
<容器>::value_type<容器>::reference<容器>::reference新聞熱點
疑難解答
圖片精選