0
0
C++programming~5 mins

String handling basics in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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++?
A<code>&lt;string&gt;</code>
B<code>&lt;iostream&gt;</code>
C<code>&lt;vector&gt;</code>
D<code>&lt;cmath&gt;</code>
What does str.length() return if str is a string?
AFirst character of <code>str</code>
BNumber of characters in <code>str</code>
CMemory size of <code>str</code>
DLast character of <code>str</code>
How do you combine two strings a and b in C++?
A<code>a + b</code>
B<code>a - b</code>
C<code>a * b</code>
D<code>a / b</code>
What is the index of the first character in a C++ string?
ADepends on the string length
B1
C-1
D0
Which of these is a valid way to declare a string variable named city with value "Paris"?
A<code>std::string city = Paris;</code>
B<code>string city = 'Paris';</code>
C<code>std::string city = "Paris";</code>
D<code>char city = "Paris";</code>
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.