Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Is the single colon In C++ Vector call, what's its function

I am trying to learn vectors; it uses confusing a ranged loop.
I Don’t understand how const int& i works in tandem with the single colon ‘:’ and vector1.

for (const int& i : vector1)
{
    cout << i << "  ";
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As of C++11, this is available. It is a range-based for loop.

In your example, i is a const reference to each item in vector1 in turn.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading