Go through the member functions of std::string class and specifically, for your purpose, check the Search member functions.
Below is an example of using find member function of std::string class for finding Operators in Equation:
#include <string>
#include <iostream>
int main()
{
std::string Operators[4] = {
"+",
"-",
"*",
"/"
};
std::string Equation = "1+1";
for (std::size_t i = 0; i < sizeof(Operators)/sizeof(Operators[0]); ++i) {
std::string::size_type n = Equation.find(Operators[i]);
std::cout << Operators[i] << " : ";
if (n == std::string::npos) {
std::cout << "not found\n";
} else {
std::cout << "found at position : " << n << '\n';
}
}
return 0;
}
Output:
# ./a.out
+ : found at position : 1
- : not found
* : not found
/ : not found
Note that, in the above program, if you change the type of Operators array to
char Operators[4] = {
'+',
'-',
'*',
'/'
};
it will work absolutely fine without any other change because the find member function has an overload which takes char as argument.
string::find_first_oforstd::any_of.