CString strHello("Hello"); strHello.AppendFormat(" %s!", "World"); // Output: "Hello World!"
int nNumber = 42; CString strOutput; strOutput.Format("The answer is %d. ", nNumber); strOutput.AppendFormat("But what is the question?"); // Output: "The answer is 42. But what is the question?"In this example, we create a CString object "strOutput" and use the Format function to set its initial value to "The answer is 42. ". We then use the AppendFormat function to append the string "But what is the question?" to the end of the existing string object, resulting in the final value "The answer is 42. But what is the question?". Package library: MFC (Microsoft Foundation Classes)