C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
来源:互联网 发布:vscode主题 编辑:程序博客网 时间:2024/05/10 15:20
参考:http://forums.codeguru.com/showthread.php?489969-no-matching-function-transform
这里介绍了 C++ STL string 大小写转换的代码,但是要注意,可能有些机器用下面的代码编译不过
#include <cctype>// toupper, tolower#include <iostream>#include <string>#include <algorithm> // transformusing namespace std;int main(){ string str = "abcdADcdeFDde!@234"; transform(str.begin(), str.end(), str.begin(), toupper); cout << str << endl; transform(str.begin(), str.end(), str.begin(), tolower); cout << str << endl; return 0;}
可能的错误提示如下:
error: no matching function for call to ‘transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unknown type>)’
这里说明了原因:
The problem is that the version of std::tolower inherited from the C standard library is a non-template function, but there are other versions of std::tolower that are function templates, and it is possible for them to be included depending on the standard library implementation. You actually want to use the non-template function, but there is ambiguity when just tolower is provided as the predicate.
翻译过来就是说,既有C版本的toupper/tolower函数,又有STL模板函数toupper/tolower,二者存在冲突。
解决办法:
在toupper/tolower前面加::,强制指定是C版本的(这时也不要include <cctype>了):
#include <iostream>#include <string>#include <algorithm> // transformusing namespace std;int main(){ string str = "abcdADcdeFDde!@234"; transform(str.begin(), str.end(), str.begin(), ::toupper); cout << str << endl; transform(str.begin(), str.end(), str.begin(), ::tolower); cout << str << endl; return 0;}
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- C++中错误no matching function for call to transform
- 【C++错误处理】no matching function for call to transform
- 【C++错误处理】no matching function for call to transform
- no matching function for call to ‘transform
- no matching function for call to ‘transform
- C++常见错误之:no matching function for call to transform
- C++ o matching function for call to 'transform...错误
- C++ o matching function for call to 'transform...错误
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- [c++]no matching function for call to ‘sort(…)......
- no matching function for call to 'sort(...),
- error: no matching function for call to
- Qt:no matching function for call to (类名)::connect()的错误原因总结
- 【求助】 no matching function for call to `strcpy(std::string&, char*&)'
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- Android开源项目
- Apache CXF实战之一 Hello World Web Service
- iOS和android调试对比
- OpenCV学习笔记(11)-K均值
- Securely Developing on Mobile
- C++ STL string 大小写转换时的 no matching function for call to ‘transform 错误
- 笔记本使用linux问题总结
- IE6 png 透明 (三种解决方法)(转来的哦)
- Apache CXF实战之二 集成Sping与Web容器
- JJTree笔记
- Apache CXF实战之三 传输Java对象
- 多屏幕多分辨率的支持和一些概念
- IE和firefox下event区别
- Apache CXF实战之四 构建RESTful Web Service