How to resolve?

Many time i tried to use the for each loop in way described as follow but it doesn’t work in my vs can any plz tell me what changes i need to do to make it workable in my vs code

   map <int,int> smallest_prime_factor ;

    smallest_prime_factor[2] = 2 ;
    smallest_prime_factor[3] = 3 ;
    smallest_prime_factor[4] = 2 ;

    for ( auto [ num , factor ] : smallest_prime_factor ) {
        cout << num << ' ' << factor << '\n' ;

It gives me following error

I use this

for ( pair<int,int> i  : smallest_prime_factor ) {
        cout << i.first << ' ' << i.second << '\n' ;

or STL Iterator

Thanks for replying
but i know this way of iterating
but if you see the way i mentioned above is handy over other ways
thats why i asked this in hope that if anyone knows will help .

1 Like
for (const auto& [key, value] :  smallest_prime_factor){
     cout << key << ":" << value << endl;
1 Like

Is your compiler configured to use C++17?


I was literally waiting for your answer. Even I didn’t get what’s happening :sweat_smile:

1 Like


This is my json file sc which depicts that i use c++17 .
I am not sure is it correct or not .

it is not working .
Giving same error .

Thanks! Please post the entirety of the code you are trying to compile.

Ugh, windows :slight_smile:

Let’s try compiling manually with your MING. From a command-prompt, something like:

C:\MinGW\bin\gcc.exe -std=c++17 <path to A.cpp>

where <path to A.cpp> should be replaced appropriately.


"cppStandard": "c++17", perhaps?

I am not good at using cmd but still i tried it says permission denied on compiling
Also i tried to by chainging gnu17 to c++17 but didn’t worked .

“Permission denied” is something else entirely. What did you type exactly and what was the precise output?

A screenshot will do, here :slight_smile:

I tried a lot to compile it using cmd but this time i was not able to do it .
as I am unknown to cmd , i don’t know the proper way of using cmd .

Try running CMD as Run as Administrator.