Answers for "see the last char of a string in cpp"

C++
4

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
Posted by: Guest on May-05-2021
0

last character of std::string

// string::back
#include <iostream>
#include <string>

int main ()
{
  std::string str ("hello world.");
  str.back() = '!';
  std::cout << str << '\n';
  return 0;
}
Posted by: Guest on June-10-2021

Code answers related to "see the last char of a string in cpp"

Browse Popular Code Answers by Language