Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind C++ String Length?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";String Length
To get the length of a string, use the length() function:
Example
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.length();Tip
You might see some C++ programs that use the size() function to get the length of a string. This is just an alias of length() . It is completely up to you if you want to use length() or size() :
Example
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.size();