Search code examples
c++macosloopsvisual-studio-codefor-range

C++ VS Code on OSX forrange loop


I'm stuck with forrange loop in VS Code. It gives me error:

expected a ';'

expected an expression

VS Code C++ error

   mp[0] = 10;
   mp[1] = 200;
   mp[2] = 3000;
   mp[3] = 40000;

   for (int id : mp) // error for ":" and ")"
   {
       std::cout << id << std::endl;
   }

Solution

  • Thank you for answer, Cory but problem still there:

    explicit type is missing ('int' assumed) [13,21]

    reference variable "item" requires an initializer [13,27]

    expected an expression [13,31]

    {
        std::map<int, int> mp;
        mp[0] = 10;
        mp[1] = 200;
        mp[2] = 3000;
        mp[3] = 40000;
    
        for (auto const &item : mp) // error for "&" and ":" and ")"
        {
            std::cout << item.first << ' ' << item.second << std::endl;
        }
    }
    

    Visual Studio Code c++11 extension warning - OSX Macbook