为什么 g++ 需要 -fallowive 标志来打印 c++ 中的迭代器值

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

本文关键字:c++ 迭代器 打印 g++ 需要 -fallowive 标志 为什么      更新时间:2023-10-16

对于以下C++代码:

 cout<<"First symbol is : "<<*it<<std::endl;

我收到以下错误:

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)

如果我通过运行来编译代码:

g++ -fpermissive

然后代码编译。请解释此行为。

您的 for 循环中可能存在错误。

您可能用分号终止了 for 循环,这结束了"it"的作用域。

它是 for 循环的局部变量。您正在尝试在循环外使用它。