std:: format_to
|
헤더 파일에 정의됨
<format>
|
||
|
template
<
class
OutputIt,
class
...
Args
>
OutputIt format_to
(
OutputIt out,
|
(1) | (C++20 이후) |
|
template
<
class
OutputIt,
class
...
Args
>
OutputIt format_to
(
OutputIt out,
|
(2) | (C++20 이후) |
|
template
<
class
OutputIt,
class
...
Args
>
OutputIt format_to
(
OutputIt out,
const
std::
locale
&
loc,
|
(3) | (C++20 이후) |
|
template
<
class
OutputIt,
class
...
Args
>
OutputIt format_to
(
OutputIt out,
const
std::
locale
&
loc,
|
(4) | (C++20 이후) |
형식 문자열 fmt 에 따라 args 를 포맷하고, 결과를 출력 반복자 out 에 기록합니다. 존재하는 경우, loc 은 로케일별 포맷팅에 사용됩니다.
다음과 동일합니다:
CharT
가
char
인 경우
(1,3)
번 오버로드에 해당하고,
wchar_t
인 경우
(2,4)
번 오버로드에 해당한다.
이러한 오버로드는
OutputIt
가 다음 개념을 만족하는 경우에만 오버로드 해결에 참여합니다:
std::
output_iterator
<
const
CharT
&
>
.
다음 조건 중 하나라도 충족되면, 동작은 정의되지 않습니다:
-
OutputIt가 std:: output_iterator < const CharT & > 를 모델링하지 않습니다. -
std::
formatter
<
Ti, CharT
>
가 일부
Args내의Ti에 대해 BasicFormatter 요구사항을 충족하지 않습니다 ( std::make_format_args 및 std::make_wformat_args 에 의해 요구됨).
목차 |
매개변수
| out | - | 출력 버퍼에 대한 반복자 | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt | - |
각 치환 필드는 다음 형식을 가집니다:
1)
형식 지정자 없는 치환 필드
2)
형식 지정자가 있는 치환 필드
|
||||||||||||||||||||||||||||||||||||||||||||||
| args... | - | 포맷팅할 인자들 | ||||||||||||||||||||||||||||||||||||||||||||||
| loc | - | std::locale 로케일별 포맷팅에 사용되는 로케일 | ||||||||||||||||||||||||||||||||||||||||||||||
반환값
출력 범위의 끝을 지난 반복자.
예외
포매터나 반복자 연산에서 발생하는 모든 예외를 전파합니다.
참고 사항
형식 문자열이 상수 표현식이 아닌 경우 오류입니다
std::runtime_format
의 결과로 초기화된 경우를 제외하고
(C++26부터)
.
std::vformat_to
는 이 요구 사항이 없습니다.
예제
#include <format> #include <iostream> #include <iterator> #include <string> int main() { std::string buffer; std::format_to ( std::back_inserter(buffer), // < OutputIt "Hello, C++{}!\n", // < fmt "20" // < arg ); std::cout << buffer; buffer.clear(); std::format_to ( std::back_inserter(buffer), // < OutputIt "Hello, {0}::{1}!{2}", // < fmt "std", // < arg {0} "format_to()", // < arg {1} "\n", // < arg {2} "extra param(s)..." // < unused ); std::cout << buffer << std::flush; std::wstring wbuffer; std::format_to ( std::back_inserter(wbuffer),// < OutputIt L"Hello, {2}::{1}!{0}", // < fmt L"\n", // < arg {0} L"format_to()", // < arg {1} L"std", // < arg {2} L"...is not..." // < unused L"...an error!" // < unused ); std::wcout << wbuffer; }
출력:
Hello, C++20! Hello, std::format_to()! Hello, std::format_to()!
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 3539 | C++20 | out could not be a move-only iterator | it can be |
| P2216R3 | C++20 | throws std::format_error for invalid format string | results in compile-time error instead |
| P2418R2 | C++20 |
objects that are neither const-usable nor copyable
(such as generator-like objects) are not formattable |
allow formatting these objects |
| P2508R1 | C++20 | there's no user-visible name for this facility |
the name
basic_format_string
is exposed
|
참고 항목
|
(C++20)
|
인수의 서식화된 표현을 새 문자열에 저장합니다
(함수 템플릿) |
|
(C++20)
|
지정된 크기를 초과하지 않도록 출력 반복자를 통해 인수의 서식화된 표현을 출력합니다
(함수 템플릿) |