#include#include using namespace std; int main() { // Create a new StringBuffer object StringBuffer buffer; // Append some text to the buffer buffer.appendText("Hello, world!"); // Print the contents of the buffer cout << buffer.toString() << endl; return 0; }
#includeIn this example, we create a new StringBuffer object and then loop through an array of strings, appending each one to the buffer along with a comma and a space. We then use the deleteRange method to remove the trailing comma and space before printing the contents of the buffer. The StringBuffer class and its methods are built-in to C++, so they don't belong to a particular package or library.#include using namespace std; int main() { // Create a new StringBuffer object StringBuffer buffer; // Loop through an array of strings and append them to the buffer string names[] = {"Alice", "Bob", "Charlie", "Dave"}; for(int i = 0; i < 4; i++) { buffer.appendText(names[i]); buffer.appendText(", "); } // Remove the trailing comma and space buffer.deleteRange(buffer.getLength() - 2, 2); // Print the contents of the buffer cout << buffer.toString() << endl; return 0; }