Iterate through a C++ Vector using a 'for' loop

后端 未结 12 1720
天命终不由人
天命终不由人 2020-11-29 16:02

I am new to the C++ language. I have been starting to use vectors, and have noticed that in all of the code I see to iterate though a vector via indices, the first parameter

12条回答
  •  暖寄归人
    2020-11-29 16:35

    Here is a simpler way to iterate and print values in vector.

    for(int x: A) // for integer x in vector A
        cout<< x <<" "; 
    

提交回复
热议问题