std::basic_string_view<CharT,Traits>::begin, std::basic_string_view<CharT,Traits>::cbegin

来自cppreference.com
 
 
 
 
constexpr const_iterator begin() const noexcept;
(C++17 起)
constexpr const_iterator cbegin() const noexcept;
(C++17 起)

返回指向视图首字符的迭代器。

range-begin-end.svg

参数

(无)

返回值

指向首字符的 const_iterator

复杂度

常数。

示例

#include <iostream>
#include <string_view>
 
int main()
{
    constexpr std::string_view str_view("abcd");
 
    constexpr auto begin = str_view.begin();
    constexpr auto cbegin = str_view.cbegin();
    static_assert(
        *begin == 'a' and
        *cbegin == 'a' and
        *begin == *cbegin and
        begin == cbegin and
        std::same_as<decltype(begin), decltype(cbegin)>);
}

参阅

返回指向结尾的迭代器
(公开成员函数)
返回指向起始的迭代器
(std::basic_string<CharT,Traits,Allocator> 的公开成员函数)