0
0
C++programming~5 mins

String functions overview in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Astrlen()
Bsize()
Ccount()
Dlength()
What does std::string::find() return if the substring is not found?
A<code>std::string::npos</code>
B-1
C0
DThrows an exception
Which function would you use to get a part of a string starting at position 3 with length 5?
Aslice(3, 5)
Bsubstring(3, 5)
Csubstr(3, 5)
Dcut(3, 5)
How do you add "world" to the end of a string s?
As.push_back("world")
Bs.add("world")
Cs.insert("world")
Ds.append("world")
Which function returns a pointer to a C-style string from a std::string?
Ac_str()
Bdata()
Cto_cstring()
Dptr()
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.