我有一个像下面如何检查这是否是std :: list的最后一个成员?
typedef std::list<std::string> SegmentValue;
然后在迭代我需要检查,如果这是最后一次迭代的列表。
for(Field::SegmentValue::const_iterator it = m_segmentValue.begin();It !=
m_segmentValue.end();It++){
if((segIt + 1) == m_segmentValue.end())//last iteration
...
}
,但我在编译得到错误:
error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::list<_Ty>::_Const_iterator<_Secure_validation>'
我怎么能检查,如果这是最后itration?
我宁愿在循环前使用'std :: prev'在'end()'上预先计算它。 – jrok 2012-07-09 15:06:01