/* Program to illustrate string processing */ #include #include using namespace std; int main() { string str = "this orchestra is fabulous"; string::size_type pos, start_position=0; string string_to_find = "orchestra"; int count=0; pos = str.find(string_to_find, start_position); //pos=5 cout << string_to_find << " was found in position " << pos << endl; pos = str.find("band",start_position); //pos=string::npos cout << "\"band\" was found in position " << pos << endl; pos = str.find("is",0); //pos=2 cout << "\"is\" was found in position " << pos << endl; pos = str.find('c',0); //pos=7 cout << "\"c\" was found in position " << pos << endl; pos = str.find("is",5); //pos=15 cout << "\"is\" was found in position " << pos << endl; pos = str.find('s', 0); cout << "\"s\" was found in position " << pos << endl; while(pos < str.npos) { count++; pos = str.find('s', pos+1); cout << "\"s\" was found in position " << pos << endl; } cout << "s was found " << count << " times." << endl; // system("pause"); //un-comment when using DevC++ return 0; }