#include#include using namespace std; int main() { // create a StringBuffer object string s = "Hello"; StringBuffer buffer(s); // append a string to the buffer buffer.append(" World!"); // output the result cout << buffer.toString() << endl; return 0; }
#includeOutput: "C++ is awesome!" In both cases, we create a StringBuffer object and use the append() method to add a string or character array to the object. The toString() method is then used to convert the StringBuffer to a string that can be printed or used elsewhere.#include using namespace std; int main() { // create a StringBuffer object StringBuffer buffer("C++"); // append a character array to the buffer char str[] = " is awesome!"; buffer.append(str); // output the result cout << buffer.toString() << endl; return 0; }