我有循環象下面這樣:檢查迭代器的最後一個元素
for (multimap<string,string>::iterator it2 = ppp.first;it2 != ppp.second; ++it2)
{
if(it2==ppp.second -1)
str=str+it2->second.substr(0,(it2->second).find('-'));
else
str=str+it2->second.substr(0,(it2->second).find('-'))+'&';
}
我使用的條件如下圖所示:
if(it2==ppp.second -1)
檢查的最後一個元素,並做一些額外的功能如果我找到最後一個元素。但上述條件不起作用。 扔的我一個錯誤:
"000001.cc", line 50: Error: The operation "__rwstd::__rb_tree<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>>, __rwstd::__select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>::iterator - int" is illegal.
1 Error(s) detected.
有誰請幫助。
可能的重複:http://stackoverflow.com/questions/151046/how-can-i-detect-the-last-iteration-in-a-loop -over-stdmap – DhruvPathak 2011-12-21 07:22:18
@dhruv。感謝鏈接。它解決了我的問題。 – Vijay 2011-12-21 07:28:10