I am just wondering what does this do
for (size_t pos : vec)
I understand that it is a for loop, but how does it work? How would you interpret it? Is there a long version of it, like:
for(size t pos = 0 ; 0 < vec...)
I am just wondering what does this do
for (size_t pos : vec)
I understand that it is a for loop, but how does it work? How would you interpret it? Is there a long version of it, like:
for(size t pos = 0 ; 0 < vec...)
It is a range-based loop. "pos" takes values from vec begin to end. For example the following code prints 1,10,100 and 1000.
#include <iostream>
using namespace std;
int main()
{
int number[] = {1,10,100,1000};
for (int pos : number)
{
cout << pos << endl;
}
return 0;
}