#include#include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString str = "Hello"; str.appendLiteral(" World!"); qDebug() << str; // Output: "Hello World!" return a.exec(); }
#includeIn this example, we create a std::string object containing the string "Hello". We then create a boost::format object representing the string literal " World!". We use boost::str to format the boost::format object with the string "World", and we use boost::io::group to show the "+" sign for positive numbers. Finally, we use the append method to append the formatted string to the end of the std::string. We output the results to the console. Both Qt and Boost libraries provide efficient implementation of StringBuilder with various features.#include #include int main() { std::string str = "Hello"; boost::format fmt("%1% World!"); str.append(boost::str(fmt % boost::io::group(std::showpos, "World"))); std::cout << str << std::endl; // Output: "Hello World!" return 0; }