C++ string back() Function
Example
Get the last character of a string:
string txt = "Hello World!";
cout << txt.back();
Definition and Usage
The back() function returns the last character of a string.
You can also use it to change the last character, like txt.back() = '?';.
The back function is defined in the <string> header file.
Tip: To get the first character, use front().
Syntax
string.back();
Parameter Values
None.
Technical Details
| Returns: | A reference to the last character of the string. |
|---|
Related Pages
Read more about strings in our String Tutorial.