#include#include int main() { std::string myString = "The value of pi is "; double pi = 3.14159; myString.appendf("%.2f", pi); std::cout << myString << std::endl; return 0; }
#includeThis example creates an ostringstream object and uses StringBuffer appendf to append the string "blue" to it. The output will be "My favorite color is blue". Package library: std::string.#include int main() { std::ostringstream oss; oss << "My favorite color is "; oss.appendf("%s", "blue"); std::cout << oss.str() << std::endl; return 0; }