std::match_results<BidirIt,Alloc>:: format
|
template
<
class
OutputIt
>
OutputIt format
(
OutputIt out,
|
(1) | (C++11부터) |
|
template
<
class
OutputIt,
class
ST,
class
SA
>
OutputIt format
(
OutputIt out,
|
(2) | (C++11부터) |
|
template
<
class
ST,
class
SA
>
std::
basic_string
<
char_type,ST,SA
>
|
(3) | (C++11부터) |
|
string_type format
(
const
char_type
*
fmt_s,
std::
regex_constants
::
match_flag_type
flags
=
|
(4) | (C++11부터) |
format
는 형식 문자열을 출력하며, 해당 문자열 내의 형식 지정자나 이스케이프 시퀀스를
*
this
에서 가져온 일치 데이터로 대체합니다.
[
fmt_first
,
fmt_last
)
로 정의됩니다. 결과 문자 시퀀스는
out
에 복사됩니다.
flags 비트마스크는 어떤 형식 지정자와 이스케이프 시퀀스가 인식되는지 결정합니다.
format
의 동작은
ready
(
)
!
=
true
일 때 정의되지 않습니다.
목차 |
매개변수
| fmt_begin, fmt_end | - | 포맷 문자 시퀀스를 정의하는 문자 범위에 대한 포인터 |
| fmt | - | std::basic_string 포맷 문자 시퀀스를 정의함 |
| fmt_s | - | 포맷 문자 시퀀스를 정의하는 널 종료 문자열에 대한 포인터 |
| out | - | 결과 문자 시퀀스가 복사되는 반복자 |
| flags | - | std::regex_constants::match_flag_type 인식되는 포맷 지정자 및 이스케이프 시퀀스를 지정하는 비트마스크 |
| 타입 요구사항 | ||
-
OutputIt
는
LegacyOutputIterator
요구사항을 충족해야 함.
|
||
반환값
예외
구현 정의 예외를 던질 수 있습니다.
예제
#include <iostream> #include <regex> #include <string> int main() { std::string s = "for a good time, call 867-5309"; std::regex phone_regex("\\d{3}-\\d{4}"); std::smatch phone_match; if (std::regex_search(s, phone_match, phone_regex)) { std::string fmt_s = phone_match.format( "$`" // $` means characters before the match "[$&]" // $& means the matched characters "$'"); // $' means characters following the match std::cout << fmt_s << '\n'; } }
출력:
for a good time, call [867-5309]
참고 항목
|
(C++11)
|
정규 표현식의 발생을 형식화된 대체 텍스트로 교체
(함수 템플릿) |
|
(C++11)
|
매칭에 특화된 옵션들
(typedef) |