Question

So I've seen a lot of similar issues but none of the answers are fixing my issue. Can someone explain why this code:

string LinkedListByName::toLower(string stringToConvert){

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

is giving me this error:

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

In the project I'm going to need to convert a lot of strings to lower and boost is NOT an option. I literally copied and pasted this code from previous projects in which it functioned.

Additionally the header file is including the following:

#include <vector>
using namespace std;
#include <iostream>
using namespace std;
#include <string>
using namespace std;
#include <algorithm>
#include "Node.h"
namespace model {
Was it helpful?

Solution

Your method should return string, but instead you try to return iterator from std::transform. Change it to this:

string LinkedListByName::toLower(string stringToConvert){
    std::transform(stringToConvert.begin(), stringToConvert.end(), stringToConvert.begin(), ::tolower); 
    return stringToConvert;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top