One of the most delightful discoveries awaiting a C programmer learning about C++ string handling is how simply strings can be combined and appended using operator+ and
operator+=. These operators make combining strings syntactically equivalent to adding numeric data. Example :
#include <string> #include <iostream> using namespace std; int main() { string s1("Humpty "); string s2("Dumpty "); string s3(", then what i do ? "); // operator+ concatenates strings s1 = s1 + s2; cout << s1 << endl; // Another way to concatenates strings s1 += s3; cout << s1 << endl; // You can index the string on the right s1 += s3 + s3[4] + "hahaha"; cout << s1 << endl; getchar(); return 0; }