How to convert std::string to lower case?

后端 未结 26 1670
旧时难觅i
旧时难觅i 2020-11-22 00:01

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

26条回答
  •  借酒劲吻你
    2020-11-22 00:25

    An alternative to Boost is POCO (pocoproject.org).

    POCO provides two variants:

    1. The first variant makes a copy without altering the original string.
    2. The second variant changes the original string in place.
      "In Place" versions always have "InPlace" in the name.

    Both versions are demonstrated below:

    #include "Poco/String.h"
    using namespace Poco;
    
    std::string hello("Stack Overflow!");
    
    // Copies "STACK OVERFLOW!" into 'newString' without altering 'hello.'
    std::string newString(toUpper(hello));
    
    // Changes newString in-place to read "stack overflow!"
    toLowerInPlace(newString);
    

提交回复
热议问题