【发布时间】:2013-01-09 17:55:57
【问题描述】:
std::vector<std::string> endpointLSRKey;
for(auto it = endpointLSRKey.begin(); it != endpointLSRKey.end(); ++it) {
lsr->setItem(0, "", *it, address);
}
然后得到一个错误说“auto”已经改变了c++11中的含义,删除它!
所以我改成这样:
for(std::string& str : endpointLSRKey){
lsr->setItem(0, "", str, address);
}
然后出现错误提示“C++98 模式下不允许基于范围的 'for' 循环”
一头雾水,怎么迭代??
为什么有时是 c++11 而有时是 c++98?
【问题讨论】:
-
看来您没有在 C++11 模式下编译。在 C++98 中, auto 具有已被删除的(大部分无用的)含义,并且它也没有基于范围的 for 循环。这意味着您在 C++98 模式下编译,而不是 C++11 模式。
-
你用的是什么编译器?如果是 GCC(我也认为是 clang),请添加标志
-std=c++0x -
什么编译器,什么设置?
-
@sharth 那么我应该如何在 c++98mode 中进行迭代?谢谢
-
std::vector<std::string>::iterator it = endpointLSRKey.begin(); ...
标签: c++ c++11 vector iterator c++98