C++ std::list crbegin() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
std::list

Definition

In C++11 and later, std::list::crbegin() returns a const reverse iterator that points at the last element of a std::list. The letters cr mean const reverse.

You can walk the list from back to front and read every element, but you cannot change any of them. Include <list> to use it.

This is a member of std::list<T>, a doubly linked list. Every element lives in its own node with a link to the previous and the next node, so a list can insert and erase anywhere quickly once you hold an iterator. It has no access by index, so l[i] does not exist.

Syntax

Call crbegin with empty brackets and pair it with crend().

C++
for (auto it = l.crbegin(); it != l.crend(); ++it) {
    std::cout << *it;           // read only
}
std::vector<int> v(l.crbegin(), l.crend());  // reversed copy
CallWhat it does
l.crbegin()Returns a const_reverse_iterator to the last element. On an empty list it equals crend().

rbegin() on a non-const list lets you write. crbegin() never does.

Library declarations
C++
const_reverse_iterator crbegin() const noexcept;   // since C++11

Parameters

ParameterDescription
Nonecrbegin() takes no parameters. Call it with empty brackets.

Return Value

Return ValueDescription
const_reverse_iteratorA read-only reverse iterator that points at the last element.

C++ Examples

Example 1 — crbegin() and crend() in a Loop

Print a list from the last element to the first one, with read-only access.

C++
#include <iostream>
#include <list>

int main() {
    std::list<char> l = {'a', 'b', 'c', 'd'};

    for (auto it = l.crbegin(); it != l.crend(); ++it) {
        std::cout << *it;
    }
    std::cout << '\n';
    return 0;
}

How It Works

  1. l.crbegin() is a read-only iterator at the last node, which holds 'd'.
  2. Each ++it moves one step toward the front: d, c, b, a.
  3. The loop stops at l.crend(). The characters were only read, never changed.

Example 2 — crbegin() to Fill Another Container

Give the two iterators to a std::vector and it builds a reversed copy of the list.

C++
#include <iostream>
#include <list>
#include <vector>

int main() {
    std::list<int> l = {10, 20, 30};

    std::vector<int> v(l.crbegin(), l.crend());

    for (int n : v) {
        std::cout << n << ' ';
    }
    std::cout << '\n';
    return 0;
}

How It Works

  1. The vector constructor copies every element from the first iterator up to the second one.
  2. Because we pass crbegin() first, the copy starts with the last list element, 30.
  3. The vector holds 30 20 10. The list l still reads 10 20 30, because we only looked at it.

Example 3 — crbegin() to Test a Palindrome

Compare the list from the front with the same list from the back, using std::equal().

C++
#include <algorithm>
#include <iostream>
#include <list>

int main() {
    std::list<int> l = {1, 2, 3, 2, 1};

    bool same = std::equal(l.cbegin(), l.cend(), l.crbegin());

    std::cout << std::boolalpha;
    std::cout << "palindrome: " << same << '\n';
    return 0;
}

How It Works

  1. std::equal() walks two sequences together and checks that matching elements are equal.
  2. The first sequence goes from the front with cbegin(), and the second one goes from the back with crbegin().
  3. The pairs are 1-1, 2-2, 3-3, 2-2, 1-1, so the result is true.

Frequently Asked Questions

A const reverse iterator that points at the last element. You can read through it, but not change the element.
rbegin() on a non-const list gives a reverse iterator that can change elements. crbegin() always gives a read-only reverse iterator.
C++11 and later.
Pass crbegin() and crend() to a constructor, for example std::vector<int> v(l.crbegin(), l.crend()); The list itself is not changed.
When the list is empty. There is nothing to visit, so a backwards loop does not run.

Next: crend()

Get a read-only reverse iterator one place before the first element (C++11) with std::list.

crend() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful