Warning 7.11.1.
Unfortunately, the
+
operator does not work on native C strings.
+
operator can be used on strings; it performs string concatenation. To concatenate means to join the two operands end to end.
+
operator to concatenate fruit
with bakedGood
to create dessert
.banana nut bread
.
+
operator does not work on native C strings.
string dessert = "banana" + " nut bread";
string
, though, C++ will automatically convert the other.
string
. In the following example, we will use concatenation and character arithmetic to output an abecedarian series.
Jack Kack Lack Mack Nack Ouack Pack Quack
string
s and not with native C strings. Unfortunately, an expression like letter + "ack"
is syntactically legal in C++, although it produces a very strange result, at least in my development environment.
string s = "C++";
string t = "rocks";
cout << s + t << endl;
C++ is so fun!
greeter
that adds “hello” and “goodbye” behind and ahead of a message respectively and then prints the new message. Example: greeter("ssup")
will print “hello ssup goodbye”