get last char in string + c code example
Example 1: c++ get last character of string
// Example
YourStr.substr(YourStr.length() - 1)
// Syntax
std::string YourStr = "abcdef";
std::cout << YourStr.substr(YourStr.length() - 1) << "\n"; // OUTPUT: f
Example 2: get last char string c
char fruit[5] = "apple";
printf("Last character : %c", fruit[strlen(fruit)-1]);