C++ · ОСНОВЫ · LESSON 13

The word and its length

string.size() · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

How it works.

You can ask the string size by size(). He counts symbols.

string word = "cat";
cout << word.size() << endl;

✦ The dot connects the string to its method.

STEP 2

Try to understand.

The dot connects the string to its method.

string word = "cat";
cout << word.size() << endl;

✦ Compare this to the first one. Then do the cool job yourself.

IN-CLASS PRACTICE

Type the code yourself

Manually type the program from the sample. So you'll remember commands and brackets.

#include <iostream>
#include <string>
using namespace std;

int main() {
    string word = "cat";
    cout << word.size() << endl;
    return 0;
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create string word = «dog» in Latin letters and output the length through size().

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework