std:: print
|
헤더 파일에 정의됨
<print>
|
||
|
template
<
class
...
Args
>
void print ( std:: format_string < Args... > fmt, Args && ... args ) ; |
(1) | (C++23부터) |
|
template
<
class
...
Args
>
void
print
(
std::
FILE
*
stream,
|
(2) | (C++23부터) |
형식 문자열 fmt 에 따라 args 를 형식화하고, 결과를 출력 스트림에 출력합니다.
? std:: vprint_unicode ( stream, fmt. str , std:: make_format_args ( args... ) )
: std :: vprint_unicode_buffered ( stream, fmt. str , std:: make_format_args ( args... ) ) ; .
? std:: vprint_nonunicode ( stream, fmt. str , std:: make_format_args ( args... ) )
: std :: vprint_nonunicode_buffered ( stream, fmt. str , std:: make_format_args ( args... ) ) ; .
만약
std::
formatter
<
Ti,
char
>
가
Args
내의 어떤
Ti
에 대해서도
BasicFormatter
요구사항을 충족하지 않는다면(이는
std::make_format_args
에 의해 요구됨), 동작은 정의되지 않습니다.
목차 |
매개변수
| stream | - | 출력할 출력 파일 스트림 | ||||||||||||||||||||||||||||||||||||||||||||||
| fmt | - |
각 치환 필드는 다음 형식을 가집니다:
1)
형식 명세 없음 치환 필드
2)
형식 명세 포함 치환 필드
|
||||||||||||||||||||||||||||||||||||||||||||||
| args... | - | 형식화할 인수들 | ||||||||||||||||||||||||||||||||||||||||||||||
예외
- std::bad_alloc 할당 실패 시.
- std::system_error , 스트림에 쓰기 작업이 실패할 경우.
- 사용된 formatters 에서 발생한 모든 예외를 전파합니다, 예를 들어 std::format_error .
참고 사항
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_print
|
202207L
|
(C++23) | 형식화된 출력 |
202403L
|
(C++26)
(DR23) |
버퍼링되지 않은 형식화된 출력 | |
202406L
|
(C++26)
(DR23) |
더 많은 형식화 가능 타입에 대한 버퍼링되지 않은 형식화된 출력 활성화 | |
__cpp_lib_format
|
202207L
|
(C++23) | std::basic_format_string 노출 |
예제
#include <cstdio> #include <filesystem> #include <print> int main() { std::print("{2} {1}{0}!\n", 23, "C++", "Hello"); // overload (1) const auto tmp{std::filesystem::temp_directory_path() / "test.txt"}; if (std::FILE* stream{std::fopen(tmp.c_str(), "w")}) { std::print(stream, "File: {}", tmp.string()); // overload (2) std::fclose(stream); } }
출력:
Hello C++23!
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| P3107R5 | C++23 | 버퍼링된 출력 작업만 수행 가능 | 버퍼링되지 않은 출력 작업 수행 가능 |
| P3235R3 | C++23 |
P3107R5
에 의해 추가된 함수 이름들이
오해의 소지가 있었음 |
함수 이름 변경 |
참고 항목
|
(C++23)
|
std::print
과 동일하지만 각 출력이 추가적인 개행으로 종료됨
(함수 템플릿) |
|
(C++23)
|
인수의
형식화된
표현을 출력함
(함수 템플릿) |
|
(C++20)
|
인수의 형식화된 표현을 새 문자열에 저장함
(함수 템플릿) |
|
(C++20)
|
출력 반복자를 통해 인수의 형식화된 표현을 기록함
(함수 템플릿) |
|
(C++11)
|
형식화된 출력을
stdout
, 파일 스트림 또는 버퍼에 출력함
(함수) |