C++查找字符串中是否有某个子串

#include<iostream>
#include<string>
using namespace std;

int main()
{
	string a = "apple  banana  orange";
	string b = "banana";
	string::size_type idx = a.find(b);
	if (idx != string::npos)
		cout << "有" << endl;
	else
		cout << "没有" << endl;
    return 0;
}

//nops表示size_type的最大值,表示不存在的位置。find成员的返回值是size_type

猜你喜欢

转载自blog.csdn.net/alike_meng/article/details/105414666
今日推荐