All lessonsOpen Open Open Open Open
7. Strings
Indexing and building strings
0 of 5 activities0%
Reading 1
Characters inside a string
s[i] is the character at index i. Indexes start at 0 and go to s.size() - 1.
You can change a character with s[i] = 'X'; Join strings with + or +=.
Looping from 0 to size()-1 visits every character.
string s = "cat";
cout << s[0] << endl; // c
s[0] = 'b';
cout << s << endl; // bat
cout << s + "s" << endl;Check 2
Last character
For string s = "code"; which expression is the last character?
Fill in 3
Append
Try it 4
Flip first letter
Try other words.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Count vowels
Read one word (lowercase letters). Print how many vowels it contains (a e i o u).
main.cpp
Loading editor…