Recall & Review
beginner
What is a string in C++?
A string in C++ is a sequence of characters used to store text. It is often handled using the <code>std::string</code> class from the Standard Library.Click to reveal answer
beginner
How do you declare and initialize a string variable in C++?
You declare a string variable using
std::string and initialize it with text inside double quotes, for example: std::string name = "Alice";Click to reveal answer
beginner
How can you find the length of a string in C++?
Use the
.length() or .size() method on a string object, for example: name.length() returns the number of characters in the string.Click to reveal answer
beginner
How do you concatenate two strings in C++?
You can use the
+ operator to join two strings, for example: std::string fullName = firstName + " " + lastName;Click to reveal answer
beginner
How do you access individual characters in a string?
You can use the square brackets
[] with an index to access characters, for example: char firstChar = name[0]; gets the first character.Click to reveal answer
Which header file must you include to use
std::string in C++?✗ Incorrect
The
<string> header defines the std::string class.What does
str.length() return if str is a string?✗ Incorrect
.length() returns how many characters the string contains.How do you combine two strings
a and b in C++?✗ Incorrect
The
+ operator joins two strings together.What is the index of the first character in a C++ string?
✗ Incorrect
String indexing in C++ starts at 0.
Which of these is a valid way to declare a string variable named
city with value "Paris"?✗ Incorrect
Strings use double quotes and must be declared with
std::string.Explain how to create, access, and find the length of a string in C++.
Think about how you handle words or sentences in code.
You got /3 concepts.
Describe how to join two strings together in C++ and why this might be useful.
Imagine putting two pieces of text side by side.
You got /3 concepts.