Is there a built in function for std::string in C++ to compare two strings alphabetically when either string can be uppercase or lowercase?

后端 未结 5 533
盖世英雄少女心
盖世英雄少女心 2021-01-18 06:08

I know for C++ that basic comparative operators can accomplish the task if both words are either entirely lower or entirely upper case. I have an array of strings and letter

5条回答
  •  长发绾君心
    2021-01-18 06:57

    Nothing standard, but if you happen to be developing for Windows or have access to a Posix interface you could use the following: https://msdn.microsoft.com/en-us/library/k59z8dwe.aspx

    // didn't run it through a compiler
    // but it would look like something like this:
    {
       using namespace std;
       string a = "HELLO"s;
       string b = "HelLO"s;
       bool bIsMatch = _stricmp(a.c_str(), b.c_str()) == 0;  // bIsMatch = true
    }
    

提交回复
热议问题