Search word and text
//text search
#include<iostream.h>
#include<string.h>
#include<iomanip>
int main(int argc, char *argv[])
{
string s1("hello");
string s2(" world");
s1+=s2;
int n;
n=s1.find('l');
if(n!=-1)
cout<<setw(25)<<"first text position="<<n<<endl;
n=s1.rfind('l');
if(n!=-1)
cout<<setw(25)<<"last text position="<<n<<endl;
n=s1.find("llo");
if(n!=-1)
cout<<setw(25)<<"first word position="<<n;
return 0;
}
Comments
Post a Comment