相关疑难解决方法(0)

我可以通过添加一个数字来增加迭代器吗?

我可以使用迭代器进行正常计算,即只需通过添加数字来增加它吗?

例如,如果我想删除元素vec[3],我可以这样做:

std::vector<int> vec;
for(int i = 0; i < 5; ++i){
      vec.push_back(i);
}
vec.erase(vec.begin() + 3); // removes vec[3] element
Run Code Online (Sandbox Code Playgroud)

它适用于我(g ++),但我不确定它是否可以保证工作.

c++ iterator

41
推荐指数
2
解决办法
3万
查看次数

增加迭代器标准映射

所有,

std::map<int, std::string> addressee;
std::map<int, std::string>::iterator it1, it2;

for( it1 = addressee.begin(); it1 != addressee().end(); it1++ )
{
    bool found = false;
    for( it2 = it1 + 1; it2 != addressee.end() && !found; it2++ )
    {
       if( it1->second == it1->second )
       {
           printf( "Multiple occurences of addressees found" );
           found = true;
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

gcc吐出错误:不匹配operator +.

这段代码是我正在尝试做的简化版本.我想我可以使用std :: advance(),但它似乎只是浪费函数调用.

有更好的解决方案吗?

c++ dictionary iterator

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

标签 统计

c++ ×2

iterator ×2

dictionary ×1