|
to
declare a string variable called name: |
apstring
name; |
|
to
assign a value to a string variable: |
name
= "Jessie"; |
|
to
input a single word to a string variable:
(cannot be used to enter a
string containing spaces) |
cin
>> name; |
|
to
input more than one word to a string variable:
(reads until '\n' (carriage
return) is detected)
('\n' is NOT stored in the string variable)
(PROBLEM: does not ignore leading whitespace) |
getline(cin,
name); |
|
to
print a string variable: |
cout
<< name; |
|
to
print a specific character of a string variable: |
cout
<< name[2]; |
|
to
compare 2 strings:
(comparisons can be made
with the operators
! =, = =, <, >, <
=, > =
The < and > operators allow for alphabetic
comparisons.) |
if
(name = = "Alexis")
if (name1 < = name2)
|
|
to
create an empty string: |
name
= ""; (no space) |