c++:algorithm-find

来源:互联网 发布:网络写手收入排行 编辑:程序博客网 时间:2024/05/17 05:29
#include <cstdio>
#include <iostream>
#include <algorithm>////
#include <cstring>
#include <string>
#include <vector>


using namespace std;
int main ()
{
   string a="abcdefg";
   cout<<a.find("a")<<endl;//输出0


   string b="fg";
   cout<<a.find(b)<<endl;      //输出1
////////////////////////////
   string c="gg";
   cout<<a.find(c)<<endl;      //返回一个虚无的数


    int k;
    k=a.find(c);
    cout<<k<<endl;
////////////////////
    //所以。。。。。
   cout<<"输入母串"<<endl;
   string y;
   cin>>y;
   cout<<"输入要查找的子串"<<endl;
   string x;
   cin>>x;
   cout<<"该子串所在的位置为---"<<endl;
   int q;
   q=y.find(x);
   if(q==-1)cout<<"查无此串"<<endl;
   else     cout<<"此串位置为"<<q+1<<endl;






    vector<string> m;
    m.push_back("hello");
    m.push_back("hello2");
    m.push_back("hello3");
    if (find(m.begin(), m.end(), "hello") == m.end())
        cout << "no" << endl;
    else
        cout << "yes" << endl;


}
0 0
原创粉丝点击