c++ 将变参传到非变参函数

#include <fmt/core.h>
#include <iostream>
#include <string>
#include <cstdarg>

template <typename... Args>
void error(const char *format, Args &&...args) {
    print_with_format(format, std::forward<Args>(args)...);
}


void print_with_format(const char *format, ...) {
    va_list args;
    va_start(args, format);
    std::string formatted = fmt::vformat(format, fmt::make_args_checked<fmt::arg_join, char>(format, args));
    va_end(args);
    std::cout << formatted << std::endl;
}

  

posted on 2025-02-02 20:08  霏霏暮雨  阅读(13)  评论(0)    收藏  举报

导航