Creation and use of strings.

Hello! this is my

You can create a variable with type string in the usual ways:

string first;
first = "Hello, ";
string second = "world.";

The first line creates an string without giving it a value. The second line assigns it the string value “Hello.” The third line is a combined declaration and assignment, also called an initialization. Normally when string values like “Hello, ” or “world.” appear, they are treated as C strings. In this case, when we assign them to an string variable, they are converted automatically to string values. We can output strings in the usual way:
cout << first << second << endl;

 

CC BY 4.0 Creation and use of strings. by Gonzalo Mata is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.