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; else cout<<"not found"<<endl; f = s1.find(s3); if(f < s1.length()) cout<<"Found at index: "<<endl; else cout<<"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; }