#include #include void main() { string a = "hello"; // good string b = a + "you"; // good // string c = "hello" + "you"; // not allowed string c = string("hello") + "you"; // ok, one way around it string d; // d += "hello" + "you"; // also not allowed d = d + "hello" + "you"; // ok, another way around it cout << a << "\n"; cout << b << "\n"; cout << c << "\n"; cout << d << "\n"; } /* why? C++ strings are objects defined in the library. C strings are just pointers to arrays of chars which contain the ascii codes of the individual characters plus a zero at the end. Even in C++, writing "string" makes a C string, not a C++ string class string includes these constructors string(); // default, makes an empty string string(const string & s); // makes a copy of an existing string string(char * s); // converts from a C string // constructors can be used to convert when one type // one type (string) is explicitly expected, and another // type (char *) is given. and these operators operator+(const string & s); // appends another string operator+(char * s); // appends a C string and may others, but not the one we wanted. It is not possible to define a new operator whose first operand is a pointer. */