String To Lower/Upper in C++

前端 未结 10 1965
挽巷
挽巷 2020-12-08 20:10

What is the best way people have found to do String to Lower case / Upper case in C++?

The issue is complicated by the fact that C++ isn\'t an English only programmi

10条回答
  •  难免孤独
    2020-12-08 20:44

    For copy-pasters hoping to use Nic Strong's answer, note the spelling error in "use_factet" and the missing third parameter to std::transform:

    locale loc("");
    const ctype& ct = use_factet >(loc);
    transform(str.begin(), str.end(), std::bind1st(std::mem_fun(&ctype::tolower), &ct));
    

    should be

    locale loc("");
    const ctype& ct = use_facet >(loc);
    transform(str.begin(), str.end(), str.begin(), std::bind1st(std::mem_fun(&ctype::tolower), &ct));
    

提交回复
热议问题