How do I use for_each to output to cout?

后端 未结 5 1466
没有蜡笔的小新
没有蜡笔的小新 2020-12-23 14:58

Is there a more straight-forward way to do this?

for_each(v_Numbers.begin(), v_Numbers.end(), bind1st(operator<<, cout));

Without an expli

5条回答
  •  暖寄归人
    2020-12-23 15:44

    Yep, but you must use std::copy algorithm:

    #include 
    #include 
    #include 
    
    int main()
    {
        std::vector a;
        // fill a...
        std::copy(a.begin(), a.end(), std::ostream_iterator(std::cout));
    }
    

提交回复
热议问题