小编use*_*170的帖子

为什么我没有使用基于C++ 11范围的for循环迭代向量?

std::vector<std::string> endpointLSRKey;

for(auto it = endpointLSRKey.begin(); it != endpointLSRKey.end(); ++it) {
        lsr->setItem(0, "", *it, address);
    }
Run Code Online (Sandbox Code Playgroud)

然后得到一个错误说"auto"改变了c ++ 11中的含义,删除它!

所以我改变它:

for(std::string& str : endpointLSRKey){
        lsr->setItem(0, "", str, address);
    }
Run Code Online (Sandbox Code Playgroud)

然后得到一个错误说"在C++ 98模式下不允许'循环'基于范围"

完全糊涂了,如何迭代它?

为什么有时它是c ++ 11而有时它是c ++ 98?

c++ iterator vector c++11 c++98

0
推荐指数
1
解决办法
1182
查看次数

标签 统计

c++ ×1

c++11 ×1

c++98 ×1

iterator ×1

vector ×1