std::vformat

Header: <format>

Format arguments held by args according to the format string fmt, and return the result as a string. If present, loc is used for locale-specific formatting.

# Declarations

std::string vformat( std::string_view fmt, std::format_args args );

(since C++20)

std::wstring vformat( std::wstring_view fmt, std::wformat_args args );

(since C++20)

std::string vformat( const std::locale& loc,
std::string_view fmt, std::format_args args );

(since C++20)

std::wstring vformat( const std::locale& loc,
std::wstring_view fmt, std::wformat_args args );

(since C++20)

# Parameters

# Return value

A string object holding the formatted result.

# Example

#include <format>
#include <iostream>
 
template<typename... Args>
inline void println(const std::format_string<Args...> fmt, Args&&... args)
{
    std::cout << std::vformat(fmt.get(), std::make_format_args(args...)) << '\n';
}
 
int main()
{
    println("{}{} {}{}", "Hello", ',', "C++", -1 + 2 * 3 * 4);
}