Usando regex:
Código [Seleccionar]
#include <iostream>
#include <string>
#include <regex>
int main()
{
std::string frase{ "Galapagar, pasar y no parar; y de parar, pagar, pagar y callar." };
std::regex buscar("\\bpagar\\b");
std::sregex_iterator ppio(frase.begin(), frase.end(), buscar);
std::sregex_iterator fin = std::sregex_iterator();
std::cout << "Encontrada(s): "
<< std::distance(ppio, fin)
<< " palabra(s) completa(s):\n";
while (ppio != fin) {
std::smatch match = *ppio;
std::cout << match.str() << "\n";
ppio++;
}
}