跟进字符串大小写转换 在消化后,我将其知识收集到一个包含C++的测试程序中(用GCC-4.6进行了标记:标记 -STD= GNU+0x),其中包括了它中描述的所有替代方法。这是测试工作的英文字母。但是,当我输入非ASCII大写字母时,如瑞典字母ÄÄÖ,它们

跟进字符串大小写转换 在消化后,我将其知识收集到一个包含C++的测试程序中(用GCC-4.6进行了标记:标记 -STD= GNU+0x),其中包括了它中描述的所有替代方法。这是测试工作的英文字母。但是,当我输入非ASCII大写字母时,如瑞典字母ÄÄÖ,它们,c++,boost,case-conversion,C++,Boost,Case Conversion,跟进字符串大小写转换 在消化后,我将其知识收集到一个包含C++的测试程序中(用GCC-4.6进行了标记:标记 -STD= GNU+0x),其中包括了它中描述的所有替代方法。这是测试工作的英文字母。但是,当我输入非ASCII大写字母时,如瑞典字母ÄÄÖ,它们都不会改变这种情况。为什么?我已经检查过源代码是否保存在UTF-8中 /*! * \file t_locale.cpp * \brief Three Ways of doing case-conversions. * \see https

跟进字符串大小写转换

在消化后,我将其知识收集到一个包含C++的测试程序中(用GCC-4.6进行了标记:标记<代码> -STD= GNU+0x),其中包括了它中描述的所有替代方法。这是测试工作的英文字母。但是,当我输入非ASCII大写字母时,如瑞典字母

ÄÄÖ
,它们都不会改变这种情况。为什么?我已经检查过源代码是否保存在UTF-8中

/*!
 * \file t_locale.cpp
 * \brief Three Ways of doing case-conversions.
 * \see https://stackoverflow.com/questions/313970/stl-string-to-lower-case
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <locale>
#include <iomanip>
#include <cassert>
#include <boost/bind.hpp>
#include <boost/algorithm/string.hpp>

int main(int argc, const char * argv[], const char * envp[])
{
    using std::cout;
    using std::endl;
    using std::string;

    string a = "ÅÄÖ";
    std::locale loc("sv_SE.UTF-8");

    auto do_assert = true;

    cout << "original: " << a << endl;

    // C++
    {
        auto b = a;
        std::transform(a.begin(), a.end(), b.begin(), 
                       std::bind2nd(std::ptr_fun(&std::tolower<char>), loc));
        cout << "tolower: " << b << endl;
        if (do_assert) assert(a != b);
        string c(b);
        std::transform(b.begin(), b.end(), c.begin(), 
                       std::bind2nd(std::ptr_fun(&std::toupper<char>), loc));
        cout << "back: " << c << endl;
        if (do_assert) assert(a == c);
    }

    // Boost Alternative A
    {
        auto b = a;
        std::transform(a.begin(), a.end(), b.begin(), 
                       boost::bind(std::tolower<char>, _1, loc));
        cout << "tolower: " << b << endl;
        if (do_assert) assert(a != b);
        string c(b);
        std::transform(b.begin(), b.end(), c.begin(), 
                       boost::bind(std::toupper<char>, _1, loc));
        cout << "back: " << c << endl;
        if (do_assert) assert(a == c);
    }

    // Boost Alternative b
    {
        auto b = boost::to_lower_copy(a); // locale safe
        cout << "tolower: " << b << endl;
        if (do_assert) assert(a != b);
        auto c = boost::to_upper_copy(b); // locale safe
        cout << "back: " << c << endl;
        if (do_assert) assert(a == c);
    }

    return 0;
}
/*!
*\t\u locale.cpp文件
*\简述进行大小写转换的三种方法。
*\参见https://stackoverflow.com/questions/313970/stl-string-to-lower-case
*/
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc、常量字符*argv[],常量字符*envp[]
{
使用std::cout;
使用std::endl;
使用std::string;
字符串a=“ÅÄÖ”;
标准::现场位置(“sv_SE.UTF-8”);
auto do_assert=true;

您是否知道您的实现是否支持
sv_SE.UTF-8
locale?否。如何检查?