You can use standard algorithm std::find
declared in header <algorithm>
It resolves two tasks. It can say whether a string is present in a container and it can provide the index of the first found element.
If you need only to determine whether a string is present in a container you can use standard algorithm std::any_of
The both algorithms have linear complexity.
If a container (for example an array) is ordered then you can use standard algorithm std::binary_search
to determine whether a string is present in the container.
An example that demonstrates the usage of standard algorithm std::find
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <iterator>
int main()
{
std::string choices[] = { "a", "b", "c" };
std::cout << "Enter a string: ";
std::string s;
std::cin >> s;
auto it = std::find( std::begin( choices ), std::end( choices ), s );
bool in_array = it != std::end( choices );
std::cout << "String "\" << s << "\" is present in the array = "
<< std::boolalpha << in_array << std::endl;
if ( in_array )
{
std::cout << "It is " << std::distance( std::begin( choices ), it )
<< " element in the array" << std::endl;
}
}
If you need a more complex condition searching an element in a container you can use standard algorithm std::find_if
that accepts a predicate as an argument.