jeudi 25 mai 2017

Using regex_match() on iterator with string in c++

working on a c++ project, I need to iterate on a string ( or char* depending the solution you could provide me ! ). So basically I'm doing this :

void Pile::evalExpress(char* expchar){
    string express = expchar
    regex number {"[+-*/]"};

    for(string::iterator it = express.begin(); it!=express.end(); ++it){
        if(regex_match(*it,number)){
            cout<<*it<<endl;
        }
    }
}

char expchar[]="234*+";
Pile calcTest;
calcTest.evalExpress(expchar);

the iterator works well ( I can put a cout<<*it<<'endl above the if statement and I get a correct output )

and then when I try to compile :

error: no matching function for call to 'regex_match(char&, std::__cxx11::regex&)'
    if(regex_match(*it,number)){
                             ^

I have no idea why this is happening, I tried to don't use iterator and iterate directly on the expchar[i] but I have the same error with regex_match()...

Regards

Vincent

Aucun commentaire:

Enregistrer un commentaire