字符串迭代器不兼容
问题描述:
这里是我的示例代码..字符串迭代器不兼容
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;
当我尝试运行程序时,我发现了以下错误
#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;
}
}
我面对这个问题很多。有时候解决方法是有效的,有时却不行。我想知道这个“字符串迭代器不兼容”错误的原因。有人能帮助我吗?
答
这种情况下的问题是itScheme
是指向p_strUrl
的迭代器,而l_itTempConst
是指向strSchemeEnd
的迭代器。因为它们指向不同的字符串,所以比较这两个迭代器是不合法的。
答
itScheme是一个迭代器转换为字符串p_strUrl l_itTempConst ISN的迭代器strSchemeEnd
您不能从不同的容器
比较迭代器