jeudi 1 mars 2018

Printing contents of a vector using auto variable

I read in a book that a shorter way to iterate through a vector is as follows:

for (auto x : v) 
{
 cout << x << "\n";
}

When I tried the same out in my compiler I got two error messages stating: "'auto' changes meaning in C++11, please remove it range based 'for' loops only available in c++11" and " 'x' maybe used uninitialized in this function"

Can someone please point out the error and the solution.

Aucun commentaire:

Enregistrer un commentaire