| 10 | using namespace std::literals; |
| 11 | |
| 12 | int main() |
| 13 | { |
| 14 | constexpr auto fmt{"{}, {}"sv}; // #A The format string |
| 15 | |
| 16 | // #B Lookahead the resulting size in bytes |
| 17 | const auto size = std::formatted_size(fmt, "Hello"sv, "World"sv); |
| 18 | |
| 19 | std::vector<char> buffer(size); // #C Preallocate the required memory |
| 20 | std::format_to(buffer.begin(), fmt, "Hello"sv, "World"sv); |
| 21 | |
| 22 | for(const auto& c : buffer) { std::cout << c; } |
| 23 | |
| 24 | std::cout << '\n'; |
| 25 | } |