-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy path007_format_format_to.cpp
More file actions
36 lines (32 loc) · 1.04 KB
/
007_format_format_to.cpp
File metadata and controls
36 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <format>
#include <iostream>
#include <iterator>
#include <string>
auto main() -> int
{
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::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;
}