2017-04-10 27 views
0

在C++中输出整个容器的正确方法是什么(在这种情况下,目标是向量和数组)?可能我想要在其中放置空格,或者按如下方式排序:输出整个矢量/数组的正确方法是什么? [C++]

1: (first element) 

2: (second element) 

3: (third element) 

等等......?

+5

的可能的复制取代i < size_of_array; [如何打印出的内容矢量?](http://stackoverflow.com/questions/10750057/how-to-print-out-the-contents-of-a-vector) – Justin

回答

0

答案是通过循环每个元素:

// Array 
for (int i = 0; i < size_of_array; ++i) { 
    std::cout << i << ": " << array[i] << "\n"; 
} 

同为一个矢量是相同的,但i < name_of_vector.size();

相关问题