展开

开发者手册

C++字符串 | Stringsstd::basic_string::rbegin

性病:基本[医]String::rback,std::basic[医]字符串:

reverse_iterator rbegin();

const_reverse_iterator rbegin() const;

const_reverse_iterator crbegin() const;

(since C++11)

将反向迭代器返回到反向字符串的第一个字符。它对应于非反转字符串的最后一个字符。

参数

%280%29

返回值

将迭代器反向到第一个字符。

例外

(none)

(until C++11)

noexcept specification: noexcept

(since C++11)

复杂性

常量。

二次

代码语言:javascript
复制
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
 
int main()
{
    std::string s("Exemplar!");
    *s.rbegin() = 'y';
    std::cout << s << '\n'; // "Exemplary"
 
    std::string c;
    std::copy(s.crbegin(), s.crend(), std::back_inserter(c));
    std::cout << c << '\n'; // "yralpmexE"
}

二次

产出:

二次

代码语言:javascript
复制
Exemplary
yralpmexE

二次

另见

rend crend (C++11)

returns a reverse iterator to the end (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。