MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / main

Function main

05.22-stdFmtFormatTo1/main.cpp:12–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace std::literals;
11
12int 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}

Callers

nothing calls this directly

Calls 1

beginMethod · 0.45

Tested by

no test coverage detected