名稱空間
變體
操作

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 <concepts>
#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)>);
}

[編輯] 參閱

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