title: How to use for each loop in c++
body: <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main() {
      string str("hello world!");
      for (auto &amp;c : str)
          c = toupper(c);
      cout &lt;&lt; str;
      return 0;
  }
  </code></pre>
  
  <p>This c++ code does not compile.
  Error msg:
      main.cpp:21: error: a function-definition is not allowed here before ':' token
  Question:
  Is there a for each loop in c++ (range for loop?)?
  what is wrong with the for each loop above?</p>
  
  <p>Thanks in advance.</p>