输入两个字符串s1和s2,在s1 中查找s2对应的字符串是否存在,若存在则输出它第一次出现的位置;若不存在,则输出“没有找到该字符串”。
#include <string>
#include <iostream>
using namespace std;
int main()
{
string s1, s2;
cout << "请输入第一个字符串:";
cin >> s1;
cout << "请输入第二个字符串:";
cin >> s2;
if (s1.find(s2) != -1)
cout << s1.find(s2)<<endl;
else
cout << "没有找到该字符串"<<endl;
system("pause");
return 0;
}