fork download
#include <iostream>
#include <string>
#include <vector>

std::vector<int> obter_posicoes(std::string texto, std::string elemento){
    std::vector<int> posicoes;
    std::size_t posicao = texto.find(elemento);

    while (posicao!=std::string::npos){
        posicoes.push_back(posicao);
        posicao = texto.find("(",posicao+1);
    }

    return posicoes;
}

int main ()
{
    std::string texto ("Na(CO5(Pt");
    std::vector<int> posicoes = obter_posicoes(texto, "(");

    for (auto posicao : posicoes){
        std::cout<<posicao<< " ";
    }


    return 0;
}
Success #stdin #stdout 0s 4468KB
stdin
Standard input is empty
stdout
2 6