vendredi 6 avril 2018

Why the regex pattern of `\d` and `\S` does not take effect in c++?

Here is my code snippet:

#include<iostream>
#include<regex>
using namespace std;
int main()
{
    string a;
    regex pattern("\d+");
    smatch res;
    while(cin>>a)
    {
        if(regex_match(a,res,pattern))
            cout<<res.str(0)<<endl;
    }
    return 0;
}

When I input numbers of "666",it fails.If I change the pattern to "\S+",it also fails with the input of "abc".What's wrong with that?

Aucun commentaire:

Enregistrer un commentaire