C++ find函数简单应用

来源:互联网 发布:js 比较两个值 编辑:程序博客网 时间:2024/04/29 19:03

find函数可在已知字符串中查找子串

#include<iostream>#include<string>using namespace std;int main(){string s1 = "Rey Dennis Steckler";string s2 = "Dennis";string s3 = "Ed Wood";int f;f = s1.find(s2);if(f < s1.length())cout<<"Found at index: "<<f<<endl;elsecout<<"not found"<<endl;f = s1.find(s3);if(f < s1.length())cout<<"Found at index: "<<endl;elsecout<<"not found"<<endl;string s4 = "bby";string s5 = "bx";cout<<s4.find_first_of(s5)<<endl;cout<<s4.find_first_not_of(s5)<<endl;return 0;}


0 0
原创粉丝点击