#include#include using namespace std; int main() { // create a StringBuffer object string message = "Hello World"; StringBuffer sb(message); // retrieve the character at index 4 char ch = sb.charAt(4); // output the character cout << "Character at index 4: " << ch << endl; return 0; }
#includeIn this example, we create a StringBuffer object called "sb" and initialize it with the string "Hello World". We use the length method to determine the length of the StringBuffer, and then retrieve the last character using the charAt method with an index position of "length - 1". This is a common technique used to retrieve the last character in a string. Package/library: The StringBuffer class is part of the standard C++ library, and is defined in the#include using namespace std; int main() { // create a StringBuffer object string message = "Hello World"; StringBuffer sb(message); // retrieve the last character in the StringBuffer char ch = sb.charAt(sb.length() - 1); // output the character cout << "Last character: " << ch << endl; return 0; }