I'm trying to convert the lowercase characters of a string into its uppercase counterpart using the std::toupper function and I'm using the std::for_each algorithm to iterate over the characters in the string.
#include <iostream>
#include <string>
#include <algorithm>
#include <locale>
std::string convert_toupper(std::string *x) {
return std::toupper(*x, std::locale());
}
int main() {
std::string x ("example");
std::for_each(x.begin(), x.end(), convert_toupper);
}
When I compile this code I'm getting this error:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from me2.cpp:3:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _Funct = std::basic_string<char> (*)(std::basic_string<char>*)]’:
me2.cpp:13:52: required from here
/usr/include/c++/4.8/bits/stl_algo.h:4417:14: error: invalid conversion from ‘char’ to ‘std::basic_string<char>*’ [-fpermissive]
__f(*__first);
^
What is the proper way of character conversion from lowercase to uppercase using std::toupper and std::for_each?