C++中判断字符串A中是不是包含字符串B

2025-04-25 03:05:40
推荐回答(2个)
回答1:

string的话可以用find函数

#include
#include
using namespace std;
int main()
{
string s="golden global view";
string r="new";
if (s.find(r) < s.length())
{
cout<<"s中包含r"< }
else
{
cout<<"s中不包含r"< }
return 0;
}

回答2:

具体怎么规定?B在A中是连续的吗?比如:A=“abcdef”,B=“acdef”,这种算不算?