Q:

Why does g++ require -fpermissive flag for printing iterator value in c++?

For the following C++ code :   
 cout<<"First symbol is : "<<*it<<std::endl;

I am getting the following error:
Transformtheexpression.cpp:50:42: error: name lookup of 'it' changed for ISO 'for' scoping [-fpermissive]

         cout<<"First symbol is : "<<*it<<std::endl;
                                      ^ Transformtheexpression.cpp:50:42: note: (if you use '-fpermissive' G++ will accept your code)

If I compile the code by running :

g++ -fpermissive

Then the code compiles.
Please explain this behavior.

A:

You likely have an error in your for loop.
You probably terminated your for loop with a semicolon, which ends the scope of "it".
It is a variable local to the for loop. You are trying to use it outside the loop.

