C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- std::array
- std::vector
- std::map
- std::map<Key,T,Compare,Allocator>::emplace
- std::map<Key,T,Compare,Allocator>::get_allocator
- std::map<Key,T,Compare,Allocator>::at
- std::map<Key,T,Compare,Allocator>::operator[]
- std::map<Key,T,Compare,Allocator>::begin, std::map<Key,T,Compare,Allocator>::cbegin
- std::map<Key,T,Compare,Allocator>::end, std::map<Key,T,Compare,Allocator>::cend
- std::map<Key,T,Compare,Allocator>::extract
- std::map<Key,T,Compare,Allocator>::merge
- std::map<Key,T,Compare,Allocator>::try_emplace
- std::map<Key,T,Compare,Allocator>::insert_or_assign
- std::map<Key,T,Compare,Allocator>::clear
- std::map<Key,T,Compare,Allocator>::map
- std::map<Key,T,Compare,Allocator>::~map
- std::map<Key,T,Compare,Allocator>::operator=
- std::map<Key,T,Compare,Allocator>::rbegin, std::map<Key,T,Compare,Allocator>::crbegin
- std::map<Key,T,Compare,Allocator>::rend, std::map<Key,T,Compare,Allocator>::crend
- std::map<Key,T,Compare,Allocator>::empty
- std::map<Key,T,Compare,Allocator>::size
- std::map<Key,T,Compare,Allocator>::max_size
- std::map<Key,T,Compare,Allocator>::insert
- std::map<Key,T,Compare,Allocator>::emplace_hint
- std::map<Key,T,Compare,Allocator>::erase
- std::map<Key,T,Compare,Allocator>::swap
- std::map<Key,T,Compare,Allocator>::count
- std::map<Key,T,Compare,Allocator>::find
- std::map<Key,T,Compare,Allocator>::contains
- std::map<Key,T,Compare,Allocator>::equal_range
- std::map<Key,T,Compare,Allocator>::lower_bound
- std::map<Key,T,Compare,Allocator>::upper_bound
- std::map<Key,T,Compare,Allocator>::key_comp
- std::map<Key,T,Compare,Allocator>::value_comp
- std::swap(std::map)
- std::erase_if (std::map)
- operator==,!=,<,<=,>,>=,<=>(std::map)
- std::map çæ¨å¯¼æå¼
- std::map<Key,T,Compare,Allocator>::value_compare
- std::unordered_map
- std::priority_queue
- std::span
- std::forward_list
- std::deque
- std::list
- std::set
- std::multiset
- std::multimap
- std::unordered_set
- std::unordered_multiset
- std::unordered_multimap
- std::stack
- std::queue
- std::vector<bool>
- ç»ç¹ææ (C++17)
- 注é
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >容å¨åº >std::map > std::map<Key,T,Compare,Allocator>::begin, std::map<Key,T,Compare,Allocator>::cbegin
std::map<Key,T,Compare,Allocator>::begin, std::map<Key,T,Compare,Allocator>::cbegin
| iterator begin(); |
(C++11 å) | |
| iterator begin() noexcept; |
(C++11 èµ·) | |
| const_iterator begin() const; |
(C++11 å) | |
| const_iterator begin() const noexcept; |
(C++11 èµ·) | |
| const_iterator cbegin() const noexcept; |
(C++11 èµ·) | |
è¿åæå map é¦å
ç´ çè¿ä»£å¨ã
è¥ map 为空ï¼åè¿åçè¿ä»£å¨å°çäº end() ã
åæ°
ï¼æ ï¼
è¿åå¼
æåé¦å ç´ çè¿ä»£å¨ã
å¤æåº¦
常æ°ã
示ä¾
è¿è¡æ¤ä»£ç
è¾åºï¼
1, 1.09 4, 4.13 9, 9.24
使ç¨èªå®ä¹æ¯è¾å½æ°ç示ä¾
è¿è¡æ¤ä»£ç
#include <cmath> #include <iostream> #include <map>  struct Point { double x, y; };  typedef Point * PointPtr; // æ¯è¾äºä¸ª Point æéç x åæ å y åæ struct PointCmp { bool operator()(const PointPtr &lhs, const PointPtr &rhs) const { return lhs->x < rhs->x; } };  int main() { // 注æå³ä½¿ x åæ ä¸æé¡ºåºï¼ map ä»å°æ x åæ ååºè¿ä»£ Point points[3] = { {2, 0}, {1, 0}, {3, 0} };  // mag æ¯å°ç»ç¹å°ååéå°å ¶å¨ x-y å¹³é¢ä¸çæ¨¡çæ å° // å°½ç®¡å ³é®æ¯æéå° Point ï¼æä»¬å¸ææ x åæ é¡ºåºèéæ Point å°åç顺åºã // è¿éè¿ä½¿ç¨ PointCmp ç±»çæ¯è¾æ¹æ³è¿è¡ã std::map<Point *, double, PointCmp> mag({ { points, 2 }, { points + 1, 1 }, { points + 2, 3 } });  // ä» 0 æ´æ¹æ¯ä¸ª y åæ ä¸ºæ¨¡ for(auto iter = mag.begin(); iter != mag.end(); ++iter){ auto cur = iter->first; // æå Node çæé cur->y = mag[cur]; // 亦å¯ä½¿ç¨ cur->y = iter->second; }  // æ´æ°å¹¶æå°æ¯ä¸ªç»ç¹ç模 for(auto iter = mag.begin(); iter != mag.end(); ++iter){ auto cur = iter->first; mag[cur] = std::hypot(cur->x, cur->y); std::cout << "The magnitude of (" << cur->x << ", " << cur->y << ") is "; std::cout << iter->second << '\n'; }  // 以åºäºèå´ç for 循ç¯éå¤ä»¥ä¸å 容 for(auto i : mag) { auto cur = i.first; cur->y = i.second; mag[cur] = std::hypot(cur->x, cur->y); std::cout << "The magnitude of (" << cur->x << ", " << cur->y << ") is "; std::cout << mag[cur] << '\n'; // 注æä¸ std::cout << iter->second << '\n'; ç¸åï¼ä¸è¿°ç // std::cout << i.second << '\n'; ä¸ä¼æå°æ´æ°ç模 } }
è¾åºï¼
The magnitude of (1, 2) is 2.23607 The magnitude of (2, 1) is 2.23607 The magnitude of (3, 3) is 4.24264 The magnitude of (1, 2.23607) is 2.44949 The magnitude of (2, 2.23607) is 3 The magnitude of (3, 4.24264) is 5.19615
åé
| è¿åæå容å¨å°¾ç«¯çè¿ä»£å¨ (å ¬å¼æå彿°) |