C++ 参考手册

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

constexpr const_reverse_iterator rbegin() const noexcept;
(C++17 起)
constexpr const_reverse_iterator crbegin() const noexcept;
(C++17 起)

返回指向逆向视图首字符的逆向迭代器。它对应非逆向视图的末字符。

range-rbegin-rend.svg

参数

(无)

返回值

指向逆向视图首字符的 const_reverse_iterator

复杂度

常数

示例

#include <algorithm>
#include <iostream>
#include <iterator>
#include <string_view>
 
int main()
{
    std::ostream_iterator<char> out_it(std::cout);
    std::string_view str_view("abcdef");
 
    std::copy(str_view.rbegin(), std::next(str_view.rbegin(), 3), out_it);
    *out_it = '\n';
 
    std::copy(str_view.crbegin(), std::next(str_view.crbegin(), 3), out_it);
    *out_it = '\n';
}

输出:

fed
fed

参阅

返回指向结尾的反向迭代器
(公开成员函数)