in a set transform to lowcase c++ errorC2664

50 Views Asked by At

I'm trying to use STL function transform to transform all the strings in a set to lowcase. But I got an error of C2664. I wonder what the wrong with my code?

set<string> mydoc;
mydoc.insert("ABCD");
transform(mydoc.begin(), mydoc.end(), mydoc.begin(), ::tolower);
copy(mydoc.begin(), mydoc.end(), output);
1

There are 1 best solutions below

0
Pixelchemist On BEST ANSWER
  1. You cannot pass a std::string to tolower.
  2. The C++11 set iterator is const.

Thus, you should probably apply tolower to each string when inserting it into the set instead of changing it afterwards because you'd have to waste time by reinserting every element into a sorted container.