我有一個像下面如何檢查這是否是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