#include#include using namespace std; int main() { string myString = "Hello World!"; myString.setChar(6, 'D'); // Replaces character at index 6 with 'D' cout << myString << endl; // Output: "Hello Dorld!" return 0; }
#includeThis function belongs to the C++ Standard Library.#include using namespace std; int main() { string myString = "Hello World"; myString.setChar(myString.length(), '!'); // Adds '!' at the end of the string cout << myString << endl; // Output: "Hello World!" return 0; }