Export (0) Print
Expand All

sub_match::operator basic_string<value_type>

Casts submatch to a string.

operator basic_string<value_type>() const;

The member operator returns str().

 

// std_tr1__regex__sub_match_operator_str.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    std::regex rx("c(a*)|(b)"); 
    std::cmatch mr; 
 
    std::regex_search("xcaaay", mr, rx); 
 
    std::csub_match sub = mr[1]; 
    std::cout << "matched == " << std::boolalpha 
        << sub.matched << std::endl; 
    std::cout << "length == " << sub.length() << std::endl; 
 
    std::csub_match::difference_type dif = std::distance(sub.first, sub.second); 
    std::cout << "difference == " << dif << std::endl; 
 
    std::csub_match::iterator first = sub.first; 
    std::csub_match::iterator last = sub.second; 
    std::cout << "range == " << std::string(first, last) 
        << std::endl; 
    std::cout << "string == " << sub << std::endl; 
 
    std::csub_match::value_type *ptr = "aab"; 
    std::cout << "compare(\"aab\") == " 
        << sub.compare(ptr) << std::endl; 
    std::cout << "compare(string) == " 
        << sub.compare(std::string("AAA")) << std::endl; 
    std::cout << "compare(sub) == " 
        << sub.compare(sub) << std::endl; 
 
    return (0); 
    } 
 
matched == true
length == 3
difference == 3
range == aaa
string == aaa
compare("aab") == -1
compare(string) == 1
compare(sub) == 0

Header: <regex>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft