我正在尝试使用 STL 函数 for_each 将字符串转换为小写,但我不知道我做错了什么。这是有问题的 for_each 行:
clean = for_each(temp.begin(), temp.end(), low);
其中 temp 是一个包含字符串的字符串。这是我为低写的函数:
void low(char& x)
{
x = tolower(x);
}
我不断收到的编译器错误是这样的:
error: invalid conversion from void (*)(char&) to char [-fpermissive]
我究竟做错了什么?
编辑:这是我正在编写的整个函数:
void clean_entry (const string& orig, string& clean)
{
string temp;
int beginit, endit;
beginit = find_if(orig.begin(), orig.end(), alnum) - orig.begin();
endit = find_if(orig.begin()+beginit, orig.end(), notalnum) - orig.begin();
temp = orig.substr(beginit, endit - beginit);
clean = for_each(temp.begin(), temp.end(), low);
}