CString strName = "John Doe"; // Check if the string is empty if (!strName.IsEmpty()) { // Print the length of the string int nLength = strName.GetLength(); cout << "The length of the name is " << nLength << endl; // Print the first character of the string char chFirst = strName.GetAt(0); cout << "The first letter of the name is " << chFirst << endl; // Replace a substring within the string strName.Replace("John", "Jane"); cout << "The new name is " << strName << endl; }
int nNumber = 100; CStr strNumber = CStr(nNumber); // Print the number as a string cout << "The number is " << strNumber << endl;In this example, we convert the integer variable "nNumber" to a null-terminated character string using CStr. We then print this value to the console.