Print spaces between each element using a fold expression

后端 未结 4 1283
猫巷女王i
猫巷女王i 2021-01-21 05:20

I am using a fold expression to print elements in a variadic pack, but how do I get a space in between each element?

Currently the output is \"1 234\", the desired outpu

4条回答
  •  醉酒成梦
    2021-01-21 05:45

    If you need space only between numbers (and not after the last or before the first too), you might do:

    template 
    void print_seq(std::index_sequence)
    {
        const char* sep = "";
        (((std::cout << sep << Is), sep = " "), ...);
    }
    

    Demo

提交回复
热议问题