이 기사에서는 C++ STL에서 match_results::cbegin() 및 match_results::cend() 함수의 작동, 구문 및 예제에 대해 논의할 것입니다.
C++ STL의 match_results란 무엇입니까?
std::match_results는 일치하는 문자 시퀀스 컬렉션을 보유하는 데 사용되는 특수 컨테이너 유사 클래스입니다. 이 컨테이너 클래스에서 정규식 일치 작업은 대상 시퀀스의 일치 항목을 찾습니다.
match_results::cbegin()이란 무엇입니까?
match_results::cbegin() 함수는
구문
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
cbegin() 예
#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() 함수는
구문
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 //random value which is past to last.
cend() 예
#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