< Previous | Contents | Next >
The first thing I do in main() is create three strings in three different ways:
string word1 = "Game"; string word2("Over"); string word3(3, ’!’);
In the first line of this group, I simply create the string object word1 using the assignment operator, the same way you’ve seen for other variables. As a result, word1 is "Game".
Next, I create word2 by placing the string object to which I want the variable set between a pair of parentheses. As a result, word2 is "Over".
Finally, I create word3 by supplying between a pair of parentheses a number followed by a single character. This produces a string object made up of the provided character, which has a length equal to the number. As a result, word3 is "!!!".
92 Chapter 3 n For Loops, Strings, and Arrays: Word Jumble