I've been trying to call std::tolower()
with a different locale but it seems that something is going wrong. My code is as follows:
int main() {
std::locale::global(std::locale("es_ES.UTF-8"));
std::thread(&function, this); // Repeated some times
// wait for threads
}
void function() {
std::string word = "HeÉllO";
std::transform(word.begin(), word.end(), word.begin(), cToLower);
}
int cToLower(int c) {
return std::tolower(c, std::locale());
}
So when I try to execute this program I get:
terminate called after throwing an instance of 'std::bad_cast'
terminate called recursively
what(): std::bad_cast
Aborted (core dumped)
Although executing return std::tolower(c);
works fine, but it just converts the 'standard' characters to lower, and not É
.
I have some threads which are executing the same function simultaneously, using C++11 and compiling with g++ (in case it has something to do with it).
I was wondering if this is the correct way to implement what I want to do, or there's some other way of doing it.
Thanks!