Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/string/basic string/rbegin"

From cppreference.com
< cpp‎ | string‎ | basic string
(reverse iterator functions do not return iterator or const_iterator)
m (Add example)
Line 24: Line 24:
 
===Complexity===
 
===Complexity===
 
Constant
 
Constant
 +
 +
===Example===
 +
{{example
 +
| code=
 +
#include <cassert>
 +
#include <string>
 +
 +
int main()
 +
{
 +
  std::string s("Exemplar!");
 +
  *s.rbegin() = 'y';
 +
  assert("Exemplary" == s);
 +
 +
  auto i = s.crbegin();
 +
  assert(s[s.size()-1] == *i);
 +
}
 +
| output=
 +
}}
  
 
===See also===
 
===See also===

Revision as of 16:28, 18 May 2014

 
 
 
std::basic_string
Member functions
Element access
Iterators
basic_string::rbeginbasic_string::crbegin
(C++11)
Capacity
Modifiers
Search
Operations
Constants
Non-member functions
I/O
Comparison
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
Numeric conversions
(C++11)(C++11)(C++11)
(C++11)(C++11)
(C++11)(C++11)(C++11)
(C++11)
(C++11)
Literals
Helper classes
Deduction guides (C++17)

 
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
const_reverse_iterator crbegin() const;
(since C++11)

Returns a reverse iterator to the first character of the reversed string. It corresponds to the last character of the non-reversed string.

Contents

Parameters

(none)

Return value

reverse iterator to the first character

Complexity

Constant

Example

#include <cassert>
#include <string>
 
int main()
{
  std::string s("Exemplar!");
  *s.rbegin() = 'y';
  assert("Exemplary" == s);
 
  auto i = s.crbegin();
  assert(s[s.size()-1] == *i);
}

See also

(C++11)
returns a reverse iterator to the end
(public member function) [edit]