-a.end()与a.end()-一不相等吗
--a.end()与a.end()-1不相等吗?
------解决方案--------------------
迭代器类型不一定都是整型。你可以验证一下vector,应该是相等的。
但对于list的迭代器,不支持operator-操作。你只能用--。
------解决方案--------------------
我试了楼主的代码, 是可以的, 输出15
编译器: gcc version 4.9.1, 供参考
------解决方案--------------------
vs2008测试不通过,list是不支持随机迭代器(-,+,-=,+=)
------解决方案--------------------
就是这样
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int>a;
int one[3] = {10, 20, 15};
a.insert(a.begin(), one, one+3);
// cout<<*(a.end()-1)<<endl;//为什么这种表达式不行?
cout<<*(--a.end())<<endl;
return 0;
}
------解决方案--------------------
迭代器类型不一定都是整型。你可以验证一下vector,应该是相等的。
但对于list的迭代器,不支持operator-操作。你只能用--。
------解决方案--------------------
我试了楼主的代码, 是可以的, 输出15
编译器: gcc version 4.9.1, 供参考
------解决方案--------------------
vs2008测试不通过,list是不支持随机迭代器(-,+,-=,+=)
------解决方案--------------------
就是这样