sub_match_operator_ltlt
sub_match_operator_ltlt (sub_match의 operator<<)
이 페이지는 C++ 정규 표현식 라이브러리에서 sub_match 객체를 출력 스트림에 기록하는 operator<< 함수에 대해 설명해요. 이 연산자를 사용하면 매칭된 부분 문자열을 직접 출력할 수 있어요.
출처: cppreference
본문
함수 정의
| template < class CharT , class Traits , class BidirIt > std :: basic_ostream < CharT , Traits >& operator << ( std :: basic_ostream < CharT , Traits >& os , const sub_match < BidirIt >& m ); | (since C++11) |
|---|
매칭된 부분 시퀀스 m의 표현을 출력 스트림 os에 써요. os << m.str()과 동일해요.
매개변수
| 매개변수 | 설명 |
|---|---|
os |
표현을 쓸 출력 스트림이에요 |
m |
출력할 sub_match 객체예요 |
반환값
os를 반환해요.
예제
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::string sentence{"Quick red fox jumped over a lazy hare."};
const std::regex re{"([A-z]+) ([a-z]+) ([a-z]+)"};
std::smatch words;
std::regex_search(sentence, words, re);
for (const auto& m : words)
// m has type `const std::sub_match<std::string::const_iterator>&`
std::cout << '[' << m << "] ";
std::cout << '\n';
}
출력:
[Quick red fox] [Quick] [red] [fox]