Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C++

C++ में match_results ऑपरेटर =

इस लेख में हम C++ STL में match_results ऑपरेटर '=' के कार्य, सिंटैक्स और उदाहरणों पर चर्चा करेंगे।

C++ STL में match_results क्या है?

std::match_results एक स्पेशलाइज्ड कंटेनर-जैसी क्लास है जिसका उपयोग कैरेक्टर सीक्वेंसेस के कलेक्शन को रखने के लिए किया जाता है जो मैच होते हैं। इस कंटेनर क्लास में एक रेगेक्स मैच ऑपरेशन टारगेट सीक्वेंस के मैच ढूंढता है।

match_results ऑपरेटर '=' क्या है

Match_results ऑपरेटर = एक इक्वैलिटी ऑपरेटर है जिसका उपयोग match_results को मान निर्दिष्ट करने के लिए किया जाता है। ऑपरेटर = का उपयोग एक match_results ऑब्जेक्ट से दूसरे में एलिमेंट्स को कॉपी या मूव करने के लिए किया जाता है।

सिंटैक्स

match_results1 = (match_results2);

पैरामीटर्स

दूसरा match_results ऑब्जेक्ट जिसका डेटा हमें एक match_results ऑब्जेक्ट में कॉपी करना है।

रिटर्न वैल्यू

यह कुछ भी नहीं लौटाता।

उदाहरण

Input: string str = "Tutorials Point"; regex R("(Tutorials)(.*)"); smatch Mat_1, Mat_2; regex_match(str, Mat_1, R); Mat_2 = Mat_1; Output: MAT 2 = Tutorials Point Tutorials Point

उदाहरण 1

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str = "Tutorials Point";
    regex R("(Tutorials)(.*)");
    smatch Mat_1, Mat_2;
    regex_match(str, Mat_1, R);
    Mat_2 = Mat_1;
    cout << "String matches: " << endl;
    for (smatch::iterator i = Mat_2.begin(); i != Mat_2.end(); i++) {
        cout << *i << endl;
    }
    return 0;
}

आउटपुट

String matches:
Tutorials Point
Tutorials
Point

उदाहरण 2

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str = "Tutorials Point";
    regex R_1("(Tutorials)(.*)");
    regex R_2("(Po)(int)(.*)");
    smatch Mat_1, Mat_2;
    regex_match(str, Mat_1, R_1);
    regex_match(str, Mat_2, R_2);
    smatch Mat;
    if (Mat_1.size() > Mat_2.size()) {
        Mat = Mat_1;
    } else {
        Mat = Mat_2;
    }
    cout << "string matches " << endl;
    for (smatch::iterator i = Mat.begin(); i != Mat.end(); i++) {
        cout << *i << endl;
    }
    return 0;
}

आउटपुट

String matches:
Tutorials Point
Tutorials
Point
  1. - C++ STL में deque::operator= और deque::operator[] फ़ंक्शन

    इस लेख में हम C++ STL में deque::operator= और deque::operator[] फ़ंक्शन के कार्य, सिंटैक्स और उदाहरणों पर चर्चा करेंगे। Deque क्या है? Deque डबल एंडेड क्यू हैं जो अनुक्रम कंटेनर हैं जो दोनों छोरों पर विस्तार और संकुचन की कार्यक्षमता प्रदान करते हैं। एक कतार डेटा संरचना उपयोगकर्ता को केवल अंत में ड

  1. - C++ STL में match max_size() फ़ंक्शन

    C++ STL में match max_size() फ़ंक्शन match_results ऑब्जेक्ट में अधिकतम एलिमेंट्स की संख्या लौटाता है जिसे match कंटेनर द्वारा धारण किया जा सकता है। यह फ़ंक्शन कोई पैरामीटर स्वीकार नहीं करता है। उदाहरण कोड #include<iostream> #include <bits/stdc++.h> using namespace std; int main() { &nbs

  1. - C++ में unordered_multimap ऑपरेटर=

    C++ फंक्शन std::unordered_multimap::operator=() पुराने को बदलकर unordered_multimap को नई सामग्री निर्दिष्ट करता है और यदि आवश्यक हो तो आकार को संशोधित करता है। std::unordered_multimap::operator=() फंक्शन की घोषणा std::unordered_map() हेडर से निम्नलिखित है। C++11 (सिंटैक्स) unordered_multimap& o