C++ find函数

来源:互联网 发布:华为数据卡槽不能换 编辑:程序博客网 时间:2024/05/29 16:22
#include <iostream>#include <vector>#include <string>#include <algorithm>  //find函数所在的头文件using namespace std;int main(){    string str = "you know how much i love you";    if(find(str.begin(),str.end(),'a') != str.end())//find函数多用于容器,查找是否含有特定元素(在此不能是字符串),返回值为迭代器        cout << "yes have" << endl;    else        cout << "no have" << endl;    if(str.find("how") != string::npos) //string 也有自己的find函数,注意:它的最后比较的不能是str.end(),应该是string::npos        cout << "ofcourse have" << endl;    else        cout << "sorry no have" << endl;    return 0;}
0 0