C++ cout auto separator

后端 未结 7 1788
半阙折子戏
半阙折子戏 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条回答
  •  误落风尘
    2020-12-13 17:51

    How about using the ostream_iterator

    int main()
    {
         std::vector data {2,3,33,45};
         std::copy(std::begin(data), std::end(data),
                   std::ostream_iterator(std::cout, " "));
         std::cout << "\n";
    }
    

提交回复
热议问题