C++ cout auto separator

后端 未结 7 1789
半阙折子戏
半阙折子戏 2020-12-13 17:36

I am wondering if there is way that std::cout automatically will insert some predefined value between printed sequences.

For example:

st         


        
7条回答
  •  猫巷女王i
    2020-12-13 17:53

    A C++17 fold expression with the comma operator can create a nice one-liner:

    [](auto &&...xs){ ((std::cout << xs << ',') , ...); }(2,3,33,45);
    

提交回复
热议问题