How to print out the contents of a vector?

后端 未结 19 1208
旧时难觅i
旧时难觅i 2020-11-22 03:46

I want to print out the contents of a vector in C++, here is what I have:

#include 
#include 
#include 
#include         


        
19条回答
  •  失恋的感觉
    2020-11-22 04:37

    Just copy the container to the console.

    std::vector v{1,2,3,4};
    std::copy(v.begin(),v.end(),std::ostream_iterator(std::cout, " " ));
    

    Should output :

    1 2 3 4
    

提交回复
热议问题