string 不区分大小写比较,出现“string iterators incompatible”debug错误
来源:互联网 发布:趣加游戏公司好吗知乎 编辑:程序博客网 时间:2024/06/07 11:13
std::string中只有compare(),是区分大小写的。今天在VS2010环境下写了一个不区分大小写比较的方法,如下:
int CompareIgnoreCase(const std::string& string1,const std::string& string2) { std::string::const_iterator i1 = string1.begin(); std::string::const_iterator i2 = string2.begin(); std::string::const_iterator string1end = string1.end(); std::string::const_iterator string2end = string2.end(); for ( ; i1 != string1end && i2 != string2end; ++i1, ++i2) { char c1 = std::toupper(*i1); char c2 = std::toupper(*i2); if (c1 < c2) return -1; if (c1 > c2) return 1; } if (i1 != string1end) return 1; if (i2 != string2end) return -1; return 0;}
当运行到,for ( ; i1 != string1end && i2 != string2end; ++i1, ++i2) ,蹦出Debug Assertion Failed! Expression:string iterators incompatible!
出现错误的源码为 xstring中
#if _ITERATOR_DEBUG_LEVEL == 2void _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; }}
后将方法参数修改便可运行成功,修改为:
int CompareIgnoreCase(std::string string1, std::string string2)
这是什么原因呢?哪位大侠解惑一下?
===============================================
以上代码为7-27所写。8-10想试一下const_cast。谁知只是将参数改为const,上述代码又不出错了。
int CompareIgnoreCase(const std::string& string1,const std::string& string2)
原因还是未知。
- string 不区分大小写比较,出现“string iterators incompatible”debug错误
- cpp不区分大小写比较字符串string
- cpp不区分大小写比较字符串string
- c++ string iterators incompatible
- string iterators incompatible
- 一个string不区分大小写查找的方法(函数)
- 比较字符串不区分大小写
- CString比较不区分大小写
- 迭代器vector iterators incompatible错误;
- 比较和不区分大小写比较
- iOS字符串比较(区分与不区分大小写比较)
- iOS字符串比较(区分与不区分大小写比较)
- 不区分大小写比较两个字符串
- C#不区分大小写的比较
- csharp 字符串比较,不区分大小写
- CompareNoCase 比较两个字符串,不区分大小写
- windows c++ 比较字符串 不区分大小写
- ios 不区分字符串大小写的比较
- MySQL 分区表 partition线上修改分区字段,后续进一步学习partition (2) --> 子分区以及对录入Null值的处理情况.
- Git学习笔记之一《起步》
- Git学习笔记之二《基础》
- SecureCRT 实用配置
- NYOJ 33-蛇形填数
- string 不区分大小写比较,出现“string iterators incompatible”debug错误
- VB6对象浏览器的用法
- 关于hevc、x265、hm的一些资源下载
- Boost.Asio 技术文档
- Java 内存区域
- NYOJ 35-表达式求值
- maven-antrun-plugin
- error LNK2019: 无法解析的外部符号 _gluGetString@4,该符号在函数 _main 中被引用
- VNC安装配置及使用