c++ - Don't understand head of for loop -


i found code snippet (a bit modified) on "cplusplus.com" reference std::vector::emplace (see http://www.cplusplus.com/reference/vector/vector/emplace/).
have worked lists , know auto keyword. don't understand head of loop.

code:

#include <iostream> #include <list>  int main () {   std::list<int> list;    list.emplace_back(100);   list.emplace_back(200);    std::cout << "list contains: ";   (auto& x: list)     std::cout << "(" << x << ") ";    return 0; } 

output: list contains: (100) (200)

pointed out in comment, it's for-each loop. loop literally means for each x in list, print x.

you confused auto& x. it's accessing reference (an alias existing variable name). can read more c++ references.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -