相关疑难解决方法(0)

为什么我不能做std :: map.begin()+ 1?

我有一个std::map,我想在第二个条目开始迭代.

我可以解决这个问题,但我很困惑为什么"明显的"语法不能编译.错误消息没有帮助,因为它引用std::string,我在这里没有使用.

这是一些代码

// Suppose I have some map ...
std::map<int, int> pSomeMap;

// This is fine ...
std::map<int, int>::const_iterator pIterOne = pSomeMap.begin();
++pIterOne;

// This doesn't compile ...
std::map<int, int>::const_iterator pIterTwo = pSomeMap.begin() + 1;
Run Code Online (Sandbox Code Playgroud)

VS2012在上面的行中给出以下错误

错误C2784:'std :: _ St​​ring_iterator <_Mystr> std :: operator +(_ String_iterator <_Mystr> :: difference_type,std :: _ St​​ring_iterator <_Mystr>)':无法推断'std :: _ St​​ring_iterator <_Mystr>'的模板参数来自'int'

谁能解释一下这里发生了什么?

c++ stl visual-c++ visual-studio-2012

9
推荐指数
2
解决办法
7338
查看次数

标签 统计

c++ ×1

stl ×1

visual-c++ ×1

visual-studio-2012 ×1