C11仿写printf(const char * format,…)
namespace sqh
{
void print(const char* format)
{
const char* s = format;
while (*s)
{
if (*s == '%' && *(++s) != '%')
{
std::runtime_error("this format is error");
}
std::cout << *s++;
}
}
template<typename T,typename ...Args>
void print(const char* format, T value, Args...args)
{
const char* s = format;
while (*s)
{
if (*s == '%' && *(++s) != '%')
{
std::cout << value;
print(++s, args...);
return;
}
std::cout << *s++;
}
std::runtime_error("extra argument provided to printf ");
}
}