Recall & Review
beginner
What does the
std::string::length() function do?It returns the number of characters in the string, excluding the null terminator.
Click to reveal answer
beginner
How do you convert a
std::string to a C-style string?Use the
c_str() function, which returns a pointer to a null-terminated character array.Click to reveal answer
intermediate
What is the purpose of
std::string::substr()?It extracts a substring from the string, starting at a given position and optionally for a given length.
Click to reveal answer
intermediate
How does
std::string::find() work?It searches for a substring or character inside the string and returns the position of the first occurrence or
std::string::npos if not found.Click to reveal answer
beginner
What does
std::string::append() do?It adds characters or another string to the end of the current string, increasing its length.
Click to reveal answer
Which function returns the length of a
std::string?✗ Incorrect
length() and size() both return the string length in C++, but length() is the most common for strings. strlen() is for C-style strings.
What does
std::string::find() return if the substring is not found?✗ Incorrect
If the substring is not found, find() returns std::string::npos, a special constant indicating no match.
Which function would you use to get a part of a string starting at position 3 with length 5?
✗ Incorrect
substr() extracts a substring from a string starting at the given position and length.
How do you add "world" to the end of a string
s?✗ Incorrect
append() adds characters or strings to the end of a std::string.
Which function returns a pointer to a C-style string from a
std::string?✗ Incorrect
c_str() returns a pointer to a null-terminated C-style string.
Explain how to find a substring inside a
std::string and handle the case when it is not found.Think about the function that searches and what it returns if no match.
You got /4 concepts.
Describe how to extract a part of a string and how to add text to the end of a string in C++.
Two common string operations: cutting and joining.
You got /5 concepts.