共用方式為


operator== <regex>

各種物件的相等比較。

template<class BidIt>
    bool operator==(const sub_match<BidIt>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator==(
        const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left,
        const sub_match<BidIt>& right);
template<class BidIt, class IOtraits, class Alloc>
    bool operator==(const sub_match<BidIt>& left,
        const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right);
template<class BidIt>
    bool operator==(const typename iterator_traits<BidIt>::value_type* left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator==(const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type* right);
template<class BidIt>
    bool operator==(const typename iterator_traits<BidIt>::value_type& left,
        const sub_match<BidIt>& right);
template<class BidIt>
    bool operator==(const sub_match<BidIt>& left,
        const typename iterator_traits<BidIt>::value_type& right);
template<class BidIt, class Alloc>
    bool operator==(const match_results<BidIt, Alloc>& left,
        const match_results<BidIt, Alloc>& right);

參數

  • BidIt
    迭代器型別。

  • IOtraits
    字串的類別。

  • Alloc
    配置器類別。

  • left
    要比較的物件。

  • right
    要比較的物件。

備註

每個範本運算子將其引數都會轉換成字串並傳回比較相等之轉換物件的結果。

當範本運算子將其引數轉換成字串時用來搭配的第一個下列轉換:

型別是樣板類別 (Template-Class) 特製化 match_results 或 sub_match 的引數呼叫 str 成員函式轉換;

型別是樣板類別 basic_string 的特製化的引數未變更;

其他引數型別傳遞引數值轉換成範本類別 basic_string的適當的特製化的建構函式。

範例

 

// std_tr1__regex__operator_eq.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
typedef std::cmatch::string_type Mystr; 
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 << "match == " << mr.str() << std::endl; 
    std::cout << "sub == " << sub << std::endl; 
    std::cout << std::endl; 
 
    std::cout << "match == match == " << std::boolalpha 
        << (mr == mr) << std::endl; 
    std::cout << "sub == sub == " << std::boolalpha 
        << (sub == sub) << std::endl; 
 
    std::cout << "string(\"aab\") == sub == " << std::boolalpha 
        << (Mystr("aab") == sub) << std::endl; 
    std::cout << "sub == string(\"aab\") == " << std::boolalpha 
        << (sub == Mystr("aab")) << std::endl; 
 
    std::cout << "\"aab\" == sub == " << std::boolalpha 
        << ("aab" == sub) << std::endl; 
    std::cout << "sub == \"aab\" == " << std::boolalpha 
        << (sub == "aab") << std::endl; 
 
    std::cout << "'a' == sub == " << std::boolalpha 
        << ('a' == sub) << std::endl; 
    std::cout << "sub == 'a' == " << std::boolalpha 
        << (sub == 'a') << std::endl; 
 
    return (0); 
    } 
 
  

需求

標頭 : <regex>

命名空間: std

請參閱

參考

<regex>

operator!= <regex>

operator< <regex>

operator<= <regex>

operator> <regex>

operator>= <regex>