为什么 g++ 需要 -fpermissive 标志来打印 c++ 中的迭代器值?
Why does g++ require -fpermissive flag for printing iterator value in c++?
对于以下 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++ -f 宽容
然后代码编译。
请解释此行为。
您的 for 循环中可能有错误。
您可能用分号终止了 for 循环,这结束了 "it" 的范围。
它是for循环的局部变量。您正在尝试在循环外使用它。
对于以下 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++ -f 宽容
然后代码编译。 请解释此行为。
您的 for 循环中可能有错误。
您可能用分号终止了 for 循环,这结束了 "it" 的范围。
它是for循环的局部变量。您正在尝试在循环外使用它。