C++ Strings
In the previous chapter, we briefly mentioned Strings and we learned that a String can hold alphanumeric data – 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. It is the same process that we used for other variables in the previous chapter: 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 a String
To assign a value to a String, just like regular variables, we simply put the name, followed by the assignment operator, and then the value:
levelName = "DastardlyCave"; playerName = "John Carmack";
Note that the values need to be enclosed in quotation marks. Just like regular variables, we can also declare and assign values in a single line:
String score = ...