std::list<T,Allocator>::end, std::list<T,Allocator>::cend
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    
|   iterator end();  | 
(C++11 前) | |
|   iterator end() noexcept;  | 
(C++11 起) | |
|   const_iterator end() const;  | 
(C++11 前) | |
|   const_iterator end() const noexcept;  | 
(C++11 起) | |
|   const_iterator cend() const noexcept;  | 
(C++11 起) | |
返回指向 list 末元素后一元素的迭代器。
此元素表现为占位符;试图访问它导致未定义行为。
参数
(无)
返回值
指向后随最后元素的迭代器。
复杂度
常数。
示例
运行此代码
#include <iostream> #include <numeric> #include <list> #include <string> int main() { std::list<int> nums {1, 2, 4, 8, 16}; std::list<std::string> fruits {"orange", "apple", "raspberry"}; std::list<char> empty; // 求和 list nums 中的所有整数(若存在),仅打印结果。 std::cout << "Sum of nums: " << std::accumulate(nums.begin(), nums.end(), 0) << "\n"; // 打印 list fruits 中的首个 fruis ,不检查是否有一个。 std::cout << "First fruit: " << *fruits.begin() << "\n"; if (empty.begin() == empty.end()) std::cout << "list 'empty' is indeed empty.\n"; }
输出:
Sum of nums: 31 First fruit: orange list 'empty' is indeed empty.
参阅
|    (C++11)  | 
   返回指向起始的迭代器   (公开成员函数)  |