Синтаксис:
#include <string> size_type find_first_of( const string &str, size_type index = 0 ) const; size_type find_first_of( const charT* str, size_type index = 0 ) const; size_type find_first_of( const charT* str, size_type index, size_type num ) const; size_type find_first_of( charT ch, size_type index = 0 ) const;
Функция find_first_of function выполняет следующие действия:
str, начиная поиск с индекса index, и возвращает string::npos, если ничего не найдено,index в поисках первых num символов строки str. Возвращает индекс первого найденного символа текущей строки, либо string::npos, если не найдено совпадений,ch в текущую строку, начиная поиск с индекса index, и возвращает string::npos, если ничего не найдено,Например, следующий код использует find_first_of, чтобы заменить все гласные в строке на звездочки:
string str = "In this house, we obey the laws of thermodynamics!"; string::size_type found = str.find_first_of("aeiouAEIOU"); while( found != string::npos ) { str[found] = '*'; found = str.find_first_of("aeiouAEIUO",found+1); } cout << str << '\n'; // код выводит "*n th*s h**s*, w* *b*y th* l*ws *f th*rm*dyn*m*cs!"
Смотрите также: find, find_first_not_of, find_last_not_of, find_last_of, rfind