如题所述
第1个回答 2016-12-12
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str("one two three four five six6 seven");
cout<<str<<endl;
string strSix("six6");
str.find(strSix);
string::size_type found = str.find(strSix);
if (found!=string::npos)
{
cout << "first '"<<strSix<<"' found at: " << found << '\n';
cout << str.substr(found, strSix.size()) <<endl;
}
else
{
cout<<"not found "<<strSix<<endl;
}
return 0;
}
#include <string>
using namespace std;
int main()
{
string str("one two three four five six6 seven");
cout<<str<<endl;
string strSix("six6");
str.find(strSix);
string::size_type found = str.find(strSix);
if (found!=string::npos)
{
cout << "first '"<<strSix<<"' found at: " << found << '\n';
cout << str.substr(found, strSix.size()) <<endl;
}
else
{
cout<<"not found "<<strSix<<endl;
}
return 0;
}