इस लेख में हम C++ STL में match_results::cbegin() और match_results::cend() फंक्शन्स के कार्य, सिंटैक्स और उदाहरणों पर चर्चा करेंगे।
C++ STL में match_results क्या है?
std::match_results एक स्पेशलाइज्ड कंटेनर-जैसी क्लास है जिसका उपयोग कैरेक्टर सीक्वेंसेस के कलेक्शन को रखने के लिए किया जाता है जो मैच होते हैं। इस कंटेनर क्लास में एक रेगेक्स मैच ऑपरेशन टारगेट सीक्वेंस के मैच ढूंढता है।
match_results::cbegin() क्या है?
match_results::cbegin() फंक्शन C++ STL में एक इनबिल्ट फंक्शन है, जो <regex> हेडर फाइल में परिभाषित है। यह फंक्शन एक कॉन्स्टेंट इटरेटर लौटाता है जो match_results कंटेनर में पहले एलिमेंट की ओर इशारा करता है। कॉन्स्टेंट इटरेटर का उपयोग कंटेनर में संशोधन करने के लिए नहीं किया जा सकता, कॉन्स्टेंट इटरेटर का उपयोग केवल कंटेनर के माध्यम से इटरेट करने के लिए किया जाता है।
सिंटैक्स
smatch_name.cbegin();
पैरामीटर्स
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह फंक्शन match_results कंटेनर के पहले एलिमेंट की ओर इशारा करने वाला कॉन्स्टेंट इटरेटर लौटाता है।
उदाहरण
Input: std::string str("TutorialsPoint"); std::smatch Mat; std::regex re("(Tutorials)(.*)"); std::regex_match(str, Mat, re); Mat.cbegin(); Output: T
उदाहरण 1
#include <iostream>
#include <string>
#include <regex>
int main() {
std::string str("Tutorials");
std::smatch Mat;
std::regex re("(Tuto)(.*)");
std::regex_match(str, Mat, re);
std::cout << "Match Found: " << std::endl;
for (std::smatch::iterator i = Mat.cbegin(); i != Mat.cend(); ++i) {
std::cout << *i << std::endl;
}
return 0;
}
आउटपुट
Match Found Tutorials Tuto rials
match_results::cend() क्या है?
match_results::cend() फंक्शन C++ STL में एक इनबिल्ट फंक्शन है, जो <regex> हेडर फाइल में परिभाषित है। यह फंक्शन एक कॉन्स्टेंट इटरेटर लौटाता है जो match_results कंटेनर के अंतिम एलिमेंट के बाद वाले एलिमेंट की ओर इशारा करता है। यह फंक्शन match_results::end() के समान ही काम करता है।
सिंटैक्स
smatch_name.begin();
पैरामीटर्स
यह फंक्शन कोई पैरामीटर स्वीकार नहीं करता।
रिटर्न वैल्यू
यह फंक्शन match_results कंटेनर के पास्ट-द-लास्ट एलिमेंट की ओर इशारा करने वाला कॉन्स्टेंट इटरेटर लौटाता है।
Input: std::string str("TutorialsPoint"); std::smatch Mat; std::regex re("(Tutorials)(.*)"); std::regex_match(str, Mat, re); Mat.cend(); Output: m // रैंडम वैल्यू जो पास्ट टू लास्ट है।
उदाहरण 2
#include <iostream>
#include <string>
#include <regex>
int main() {
std::string str("Tutorials");
std::smatch Mat;
std::regex re("(Tuto)(.*)");
std::regex_match(str, Mat, re);
std::cout << "Match Found: " << std::endl;
for (std::smatch::iterator i = Mat.cbegin(); i != Mat.cend(); ++i) {
std::cout << *i << std::endl;
}
return 0;
}
आउटपुट
Match Found Tutorials Tuto rials