//for( unsigned int i=0; i < c.size(); i++ ) tolower( c[i] );
for_each( c.begin(), c.end(), tolower );
I am trying to use a for_each loop in place of the for loop for an assignment.
I am unsure why I am getting this error message:
In function âvoid clean_entry(const std::string&, std::string&)â:
prog4.cc:62:40: error: no matching function for call to âfor_each(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â
Write:
Or :
I’ve faced this problem so many times that I’m tired of fixing this in my code, as well as in others’ code.
Reason why your code is not working : there is another overloaded function
tolowerin the namespacestdwhich is causing problem when resolving the name, because the compiler is unable to decide which overload you’re referring to, when you simply passtolower1. That is why the compiler is sayingunresolved overloaded function typein the error message, which indicates the presence of overload(s).So to help the compiler in resolving to the correct overload, you’ve to cast
tolowerasthen the compiler gets the hint to select the global
tolowerfunction, which in other ways, can be used by writing::tolower.1. I guess you’ve written
using namespace stdin your code. I would also suggest you to not to do that. Use fully-qualified names in general.By the way, I think you want to transform the input string into lower case, if so, then
std::for_eachwouldn’t do that. You’ve to usestd::transformfunction as: