查找两个字符串中的公共字符;
返回公共字符的索引;
#include<iostream> #include<string> using namespace std; int main() { string s = "**Gteate Wall**!"; string t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; cout<<"s: "<<s<<endl; cout<<"t: "<<t<<endl; int first=s.find_first_of(t); if(first == string::npos){ cout<<"s中所有字符均不在t中"<<endl; }else { cout<<"s中出现在t中的字符的第一个字符:"<<s[first]<<endl; } int last = s.find_last_of(t); if(last == string::npos){ cout<<"s中所有字符均不在t中"<<endl; return 1; }else { cout<<"s中出现在t的字符的最后一个字符:"<<s[last]<<endl; return 1; } }