【发布时间】:2013-06-30 18:17:57
【问题描述】:
我有这个奇怪的错误,代码之前可以工作,但过了一段时间它停止编译。 错误是:
Could not find a match for 'std::transform<InputIterator,OutputIterator,UnaryOperation>(char *,char *,char *,charT (*)(charT,const locale &))' in function main()
它所指的行是:
string ans;
cin>>ans;
std::transform(ans.begin(), ans.end(), ans.begin(), ::tolower);
有人可以帮我解释一下为什么会这样吗? 我使用的包括:
#include <fstream.h>;
#include <iostream.h>;
#include <string>;
#include <time.h>;
#include <vector>;
using namespace std;
非常感谢
【问题讨论】:
-
@Samoth 使用指针作为迭代器有什么问题?
-
问题出在
::tolower,而不是迭代器。您不能直接传递该函数,因为它需要两个参数。见这里:stackoverflow.com/a/314163/777186 -
啊哈,找到了:en.cppreference.com/w/cpp/locale/tolower 最近有人在你的代码中添加了
#include <locale>吗? -
您应该发布一个完整的(但最少的)示例,显示您使用的包含以及任何 using 指令和/或声明。
-
<fstream.h>等都是非标准的。使用<fstream>、<iostream>和<ctime>。
标签: c++ templates runtime transform lowercase