std::basic_string<CharT,Traits,Allocator>::end, std::basic_string<CharT,Traits,Allocator>::cend
来自cppreference.com
                    
                                        
                    < cpp | string | basic string
                    
                                                            
                    | (1) | ||
|   iterator end();  | 
(C++11 前) | |
|   iterator end() noexcept;  | 
 (C++11 起)  (C++20 前)  | 
|
|   constexpr iterator end() noexcept;  | 
(C++20 起) | |
| (2) | ||
|   const_iterator end() const;  | 
(C++11 前) | |
|   const_iterator end() const noexcept;  | 
 (C++11 起)  (C++20 前)  | 
|
|   constexpr const_iterator end() const noexcept;  | 
(C++20 起) | |
| (3) | ||
|   const_iterator cend() const;  | 
(C++11 前) | |
|   const_iterator cend() const noexcept;  | 
 (C++11 起)  (C++20 前)  | 
|
|   constexpr const_iterator cend() const noexcept;  | 
(C++20 起) | |
返回指向后随字符串末字符的字符的迭代器。此字符表现为占位符,试图访问它导致未定义行为。
参数
(无)
返回值
指向后随尾字符的字符的迭代器。
复杂度
常数。
注解
在 libstdc++ 中,cend() 不能在 C++98 模式中使用。
示例
运行此代码
#include <algorithm> #include <iostream> #include <iterator> #include <string> int main() { std::string s("Exemparl"); std::next_permutation(s.begin(), s.end()); std::string c; std::copy(s.cbegin(), s.cend(), std::back_inserter(c)); std::cout << c << '\n'; // "Exemplar" }
输出:
Exemplar
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 | 
|---|---|---|---|
| LWG 1192 | C++98 |  std::string 没有成员函数 cend()
 | 
已添加 | 
参阅
|   返回指向起始的迭代器  (公开成员函数)  | |
|   返回指向结尾的迭代器  ( std::basic_string_view<CharT,Traits> 的公开成员函数)  |