search()

Given two sequences, search() returns an iterator that addresses the first position in the first sequence in which the second sequence occurs. If the subsequence does not occur, an iterator that addresses the end of the first sequence is returned. For example, within Mississippi, the subsequence iss occurs twice, and search() returns an iterator to the start of the first instance. An optional fifth parameter allows the user to override the default equality operator.

#include <algorithm> 

char str[25] = "a fine and private place"; 
char substr[4]  = "ate"; 
int *piter = search( str,str+25,substr,substr+4 ); 

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.