I have a problem with strings

So i have to write a program that reads two strings and prints out yes, if the second one is a substring of the first, and no if it's not. I would really appreciate your help. Here is my code:

{
string str;
cout << "Type a word: ";
cin >> str;
string str2;
cout << "Type another word: ";
cin >> str2;

size_t found = str.find(str2);

if (found != string::npos)
{
cout << "YES!" << found << endl;
}

else if (found == string::npos)
{
cout << "NO!" << endl;
}
You need to put your code inside the main function. You also need to include <iostream> (because you use std::cout and std::endl) and <string> (because you use std::string).
Yes, the code is put in the main function, and i also include <iostream> and <string> i just didn't copy them. The problem is somewhere else
So what's the problem you're having with your code?
i don't know. Maybe i haven't compile it correctly the last time. I tried again and the program works
Topic archived. No new replies allowed.