How to convert std::string to lower case?

后端 未结 26 2076
旧时难觅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:40

    On microsoft platforms you can use the strlwr family of functions: http://msdn.microsoft.com/en-us/library/hkxwh33z.aspx

    // crt_strlwr.c
    // compile with: /W3
    // This program uses _strlwr and _strupr to create
    // uppercase and lowercase copies of a mixed-case string.
    #include 
    #include 
    
    int main( void )
    {
       char string[100] = "The String to End All Strings!";
       char * copy1 = _strdup( string ); // make two copies
       char * copy2 = _strdup( string );
    
       _strlwr( copy1 ); // C4996
       _strupr( copy2 ); // C4996
    
       printf( "Mixed: %s\n", string );
       printf( "Lower: %s\n", copy1 );
       printf( "Upper: %s\n", copy2 );
    
       free( copy1 );
       free( copy2 );
    }
    

提交回复
热议问题