9

別のロケールで呼び出そうとしていstd::tolower()ますが、何か問題が発生しているようです。私のコードは次のとおりです。

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());
}

したがって、このプログラムを実行しようとすると、次のようになります。

terminate called after throwing an instance of 'std::bad_cast'
terminate called recursively
  what():  std::bad_cast
Aborted (core dumped)

実行return std::tolower(c);はうまくいきますが、「標準」文字を小文字に変換するだけで、É.

C++ 11を使用し、g ++でコンパイルして、同じ関数を同時に実行しているスレッドがいくつかあります(それが関係している場合)。

これが私がやりたいことを実装する正しい方法なのか、それとも他の方法があるのか​​ 疑問に思っていました。

ありがとう!

4

2 に答える 2