Sign in

gwj / po_oopc · Files

GitLab

  • Go to dashboard
  • Project
  • Activity
  • Files
  • Commits
  • Network
  • Graphs
  • po_oopc
  • examples12
  • typesafe_printf.cpp
  • Reformatted code
    c0b14c54
    Grzegorz Jabłoński authored
    2022-09-16 14:36:36 +0200  
    Browse Code »
typesafe_printf.cpp 414 Bytes
Edit Raw Blame History
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
using namespace std;
#include <string.h>

void mprintf(const char* s)
{
    cout << s;
}

template <typename C, typename... T>
void mprintf(const char* s, C d1, T... data)
{
    while (*s && *s != '%')
        if (*s)
            cout << *s++;
    if (*s == '%')
        s++;
    cout << d1;
    mprintf(s, data...);
}

int main()
{
    mprintf("ala % ma % kotów i % psów\n", 1, 2.5, 5.5);
}