Hi, I'm trying to write a program that generates a random letter and checks if a name entered contains it. The problem is on line 12 it says the class has no member contains.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <random>
#include <string>
usingnamespace std;
int main()
{
string name;
cout << "Please enter your name.";
cin >> name;
char cch = 'a' + rand() % 26;
constauto test = name;
if (test.contains(cch))
{
cout << "Your name contains the random letter we found that is " + cch;
}
}
std::string has no member function "contains". You need to look at the documentation for std::string to see what functions exist. In this case you could use "find".