#include#include int main() { std::string name = "John"; std::string emptyName = ""; std::stringbuilder builder; builder.append("Hello, "); builder.append(name); std::cout << builder.isEmpty() << std::endl; //false builder.clear(); std::cout << builder.isEmpty() << std::endl; //true builder.append(emptyName); std::cout << builder.isEmpty() << std::endl; //true return 0; }
#includeIn this example, we create a StringBuilder object named 'builder' and call the isEmpty function to check if it is empty or not. Since we have not added any string to the object, the function returns true. We then append a string to the object and again call the isEmpty function to check if it is empty or not. This time, the function returns false.#include int main() { StringBuilder builder; std::cout << builder.isEmpty() << std::endl; //true builder.append("Hello, world!"); std::cout << builder.isEmpty() << std::endl; //false return 0; }