0

所以我见过很多类似的问题,但没有一个答案能解决我的问题。有人可以解释为什么这段代码:

string LinkedListByName::toLower(string stringToConvert){

return std::transform(stringToConvert.begin(), stringToConvert.end(), stringToConvert.begin(), ::tolower); }

给我这个错误:

conversion from `__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to non-scalar type `std::string' requested

在项目中,我需要将很多字符串转换为较低的字符串,而 boost 不是一种选择。我从字面上复制并粘贴了以前运行它的项目中的代码。

此外,头文件还包括以下内容:

#include <vector>
using namespace std;
#include <iostream>
using namespace std;
#include <string>
using namespace std;
#include <algorithm>
#include "Node.h"
namespace model {
4

1 回答 1

3

您的方法应该返回字符串,但您尝试从 std::transform 返回迭代器。将其更改为:

string LinkedListByName::toLower(string stringToConvert){
    std::transform(stringToConvert.begin(), stringToConvert.end(), stringToConvert.begin(), ::tolower); 
    return stringToConvert;
}
于 2013-02-24T02:06:14.087 回答