C++ strings
In the previous chapter we briefly mentioned strings and we learned that a string can hold alphanumeric data in anything from a single character to a whole book. We didn't look at declaring, initializing, or manipulating strings. So let's do that now.
Declaring strings
Declaring a string variable is simple. We state the type, followed by the name:
String levelName; String playerName;
Once we have declared a string we can assign a value to it.
Assigning a value to strings
To assign a value to a string, as with regular variables, we simply put the name, followed by the assignment operator, then the value:
levelName = "Dastardly Cave"; playerName = "John Carmack";
Note that the values need to be enclosed in quotation marks. As with regular variables we can also declare and assign values in a single line:
String score = "Score = 0"; String message = "GAME OVER!!";
This is how we can change our string variables.