Hey everyone,
im trying to get to know vectors but i came to a point that my current knowledge stops and i need more help,
i found a program which i would like to understand but i couldn't figure it out.
here is the code:
can somebody explain to me line 1,2 and three (where it is shown as comments)
in detail because i am really struggling to understand how it works thanks a lot
- line 1 will iterate from the first element to the last element of v1; for each element (of type char in this case) it will call the function islowerCase() (passed as a function pointer). If islowerCase() returns true, the element will be removed from the vector; if it returns false, it will be kept. In other words, line 1 removes all the lowercase letters in the vector.
- line 2 will instantiate an ostream_iterator associated to the standard output. An ostream_iterator makes it easy to insert several elements of the same type to an output stream (here cout), as you will see in line 3
- line 3 is equivalent to this for loop:
1 2 3 4
for (size_t i = 0; i < v1.size(); ++i)
{
screen = v1[i]; // thank to ostream_iterator, this line is equivalent to: cout << v1[i]
}
In other words, lines 2 & 3 write the elements of v1 to the standard output.