Searching – find()
We can use the find() function of the std::string class to check whether a given character or a substring is present in the string or a part of string.
Syntax of find()
str1.find(var);
Parameters
- var: It can be a C style string, C++ style string, or a character that is to be searched in the string.
Return Value
- It returns the pointer to the first occurrence of the character or a substring in the string.
Example
std::string text = "C++ Programming"; int position = text.find("Programming"); // Find the position of a substring
The position variable will contain 4 which is the start of the first occurrence of the string “Programming” in string text.
String Functions In C++
A string is referred to as an array of characters. In C++, a stream/sequence of characters is stored in a char array. C++ includes the std::string class that is used to represent strings. It is one of the most fundamental datatypes in C++ and it comes with a huge set of inbuilt functions. In this article, will look at the functions of string computations.