foreach not recognized in C++

前端 未结 9 1377
离开以前
离开以前 2021-01-21 08:07

In my the cs106b book we use the expression \"foreach\" to go through a list of words in a Map. I implemented the code and banged my head against the wall facing mysterious erro

9条回答
  •  难免孤独
    2021-01-21 08:36

    foreach doesn't exist in C++.

    In the latest version of C++ which is only just released in some of the latest compilers, you can use "Range-based for-loop" .. find it on this page: http://en.wikipedia.org/wiki/C%2B%2B0x

    I doubt though that your compiler supports that. So, maybe stick with a for loop for now.

提交回复
热议问题