C++ 参考手册

位置:首页 > C++ 参考手册 >字符串库 >std::basic_string_view > std::basic_string_view<CharT,Traits>::end, std::basic_string_view<CharT,Traits>::cend

constexpr const_iterator end() const noexcept;
(C++17 起)
constexpr const_iterator cend() const noexcept;
(C++17 起)

返回指向视图末字符后一字符的迭代器。此字符表现为占位符,试图访问它会导致未定义行为。

range-begin-end.svg

参数

(无)

返回值

指向末字符后一字符的 const_iterator

复杂度

常数

示例

#include <iostream>
#include <iterator>
#include <string_view>
 
int main()
{
    std::string_view str_view("abcd");
 
    auto end = str_view.end();
    auto cend = str_view.cend();
 
    std::cout << *std::prev(end) << '\n';
    std::cout << *std::prev(cend) << '\n';
 
    std::cout << std::boolalpha << (end == cend) << '\n';
}

输出:

d
d
true

参阅

返回指向起始位置的迭代器
(公开成员函数)