程序go 2008-11-24 11:49 采纳率: 100%
浏览 747

如何将 std: : string 转换为小写?

I want to convert a std::string to lowercase. I am aware of the function tolower(), however in the past I have had issues with this function and it is hardly ideal anyway as use with a std::string would require iterating over each character.

Is there an alternative which works 100% of the time?

转载于:https://stackoverflow.com/questions/313970/how-to-convert-stdstring-to-lower-case

  • 写回答

20条回答 默认 最新

  • 关注

    There is a Boost string algorithm for this:

    #include <boost/algorithm/string.hpp>    
    
    std::string str = "HELLO, WORLD!";
    boost::algorithm::to_lower(str); // modifies str
    

    Or, for non-in-place:

    #include <boost/algorithm/string.hpp>    
    
    const std::string str = "HELLO, WORLD!";
    const std::string lower_str = boost::algorithm::to_lower_copy(str);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)