std::basic_string_view<CharT,Traits>::end, std::basic_string_view<CharT,Traits>::cend

出自cppreference.com
 
 
 
 
constexpr const_iterator end() const noexcept;
(C++17 起)
constexpr const_iterator cend() const noexcept;
(C++17 起)

返回指向視圖末字符後一字符的迭代器。此字符表現為占位符,試圖訪問它會導致未定義行為。

參數

(無)

返回值

指向末字符後一字符的 const_iterator

複雜度

常數。

示例

#include <iostream>
#include <iterator>
#include <string_view>

int main()
{
    constexpr std::string_view str_view("abcd");
    constexpr auto end = str_view.end();
    constexpr auto cend = str_view.cend();

    static_assert
    (
        *std::prev(end) == 'd' && 'd' == *std::prev(cend) and end == cend
    );
}

參閱

返回指向起始位置的迭代器
(公開成員函數) [編輯]
(C++11)
返回指向末尾的迭代器
(std::basic_string<CharT,Traits,Allocator> 的公開成員函數) [編輯]