Search⌘ K

Search

Explore various string searching methods in C++ to locate characters and substrings efficiently. Learn how to use functions such as find, rfind, and their variations to search forward, backward, and find character presence or absence within strings. This lesson helps you understand the indexes returned by these search operations and prepares you to apply them in practical programming scenarios.

We'll cover the following...

C++ offers many ways to search in a string. Each way exists in various overloaded forms.

ℹ️ Search is called find
It seems a bit odd but the algorithms for searching in a string start with the prefix “find”. If the search was successful, we get an index of type std::string::size_type, if not, we get the constant std::string::npos. The first character has the index 0. ...