Reputation: 1269
Here is my sample code ..
const std::string strSchemeEnd("://");
StringConstIteratorType itScheme = std::search(p_strUrl.begin(), p_strUrl.end(), strSchemeEnd.begin(), strSchemeEnd.end());
StringConstIteratorType l_itTempConst = p_strUrl.begin();
m_strScheme.reserve(std::distance(l_itTempConst, itScheme));
std::copy(l_itTempConst , itScheme, std::back_inserter(m_strScheme));
boost::algorithm::to_lower(m_strScheme);
l_itTempConst = strSchemeEnd.end();
if ( itScheme == l_itTempConst )
return;
When I try to run the program, I find the following errors
#if _ITERATOR_DEBUG_LEVEL == 2
void _Compat(const _Myiter& _Right) const
{ // test for compatible iterator pair
if (this->_Getcont() == 0
|| this->_Getcont() != _Right._Getcont())
{ // report error
_DEBUG_ERROR("string iterators incompatible");
_SCL_SECURE_INVALID_ARGUMENT;
}
}
I face this problem a lot. Sometimes a workaround works and sometimes it doesn't. I want to know the cause of this "string iterators incompatible" error. Can somebody help me ?
Upvotes: 3
Views: 3850
Reputation: 2436
itScheme is an iterator into string p_strUrl l_itTempConst isn an iterator into strSchemeEnd
You cannot compare iterators from different containers
Upvotes: 4
Reputation: 8027
The problem in this case is that itScheme
is an iterator pointing to p_strUrl
and l_itTempConst
is an iterator pointing to strSchemeEnd
. Because they are pointing at different strings it is not legal to compare these two iterators.
Upvotes: 6