#include#include using namespace std; int main() { string str = "hello world"; string substr = " my"; str.insert(5, substr); cout << str << endl; // outputs "hello my world" return 0; }
#includeIn this example, we want to insert a comma into the original string at position 5. To do this, we create a character variable 'ch' that contains the comma, and then use the insert method to insert it into the original string at position 5. Overall, the C++ string insert function is a powerful tool for manipulating strings in your code. Its functionality is built into the#include using namespace std; int main() { string str = "hello world"; char ch = ','; str.insert(5, 1, ch); cout << str << endl; // outputs "hello, world" return 0; }