std::{{{1}}}::back
From cppreference.com
Template:cpp/container//sidebar Template:ddcl list begin <tr class="t-dcl ">
<td class="t-dcl-nopad">reference back();
</td>
<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad">const_reference back() const;
</td>
<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end
Returns reference to the last element in the container.
Contents |
Parameters
(none)
Return value
reference to the last element
Complexity
Constant
Example
The following code uses back
to display the last element of a std::{{{1}}}<char>:
Run this code
#include <{{{1}}}> #include <iostream> int main() { std::{{{1}}}<char> letters {'o', 'm', 'g', 'w', 't', 'f'}; if (!letters.empty()) { std::cout << "The last character is: " << letters.back() << '\n'; } }
Output:
The last character is f