How to print out the contents of a vector?

后端 未结 19 1214
旧时难觅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:16

    In C++11, a range-based for loop might be a good solution:

    vector items = {'a','b','c'};
    for (char n : items)
        cout << n << ' ';
    

    Output:

    a b c 
    

提交回复
热议问题