#include <string>
using namespace std;
int main()
{
string Str1,Str2;
int n;
cout<<"输入字符串1 :";
cin>>Str1;
cout<<"输入字符串2 :";
cin>>Str2;
if((n=Str1.find(Str2,0))!=string::npos)
cout<<n<<endl;
else
cout<<-1<<endl;
return 0;
}
测试结果:
输入字符串1 :abcdefg123
输入字符串2 :cde
2
请按任意键继续. . .
输入字符串1 :abcdefg
输入字符串2 :123
-1
请按任意键继续. . .