C++ String Library - back


Advertisements


Description

It returns a reference to the last character of the string.

Declaration

Following is the declaration for std::string::back.

char& back();

C++11

const char& back() const;

Parameters

none

Return Value

It returns a reference to the last character of the string.

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for std::string::back.

Live Demo
#include <iostream>
#include <string>

int main () {
   std::string str ("sairamkrishna mammahe.");
   str.back() = '!';
   std::cout << str << '\n';
   return 0;
}
sairamkrishna mammahe!

string.htm

Advertisements