jeudi 24 septembre 2015

What does std::match_results::size return?

I'm a bit confused about the following C++11 code:

#include <iostream>
#include <string>
#include <regex>

int main()
{
    std::string haystack("abcdefabcghiabc");
    std::regex needle("abc");
    std::smatch matches;
    std::regex_search(haystack, matches, needle);
    std::cout << matches.size() << std::endl;
}

I'd expect it to print out 3 but instead I get 1. Am I missing something?

Aucun commentaire:

Enregistrer un commentaire