g++ error: ‘stricmp’ was not declared in this scope (but OK for 'strcmp')

前端 未结 5 1627
[愿得一人]
[愿得一人] 2020-12-09 02:26

I am trying to compile the following very very simple piece of source code:

#include 
// #include 
// using namespace std;

cl         


        
相关标签:
5条回答
  • 2020-12-09 02:39

    Add a define for it to overwrite stricmp with strcasecmp on the platforms you are looking for.

    #ifdef _IPHONE <- your platform define here
    #define stricmp strcasecmp
    #define strnicmp strncasecmp
    #endif
    

    Then you can just use stricmp always.

    0 讨论(0)
  • 2020-12-09 02:56

    Try strcasecmp(). Here's the manual page for it. It is conforming to 4.4BSD and POSIX.1-2001.

    0 讨论(0)
  • 2020-12-09 02:57

    Pretty easy to make your own if need be...

    int my_stricmp (const char *s1, const char *s2)
    {
        while (*s1 != 0 && *s2 != 0)
        {
            if (*s1 != *s2 && ::toupper (*s1) != ::toupper(*s2))
            {
                return -1;
            }
            s1++;
            s2++;
        }
        return (*s1 == 0 && *s2 == 0) ? 0 : -1;
    }
    
    0 讨论(0)
  • 2020-12-09 02:59

    If you've got Boost, use boost::algorithm::iequals(s1, s2, std::locale::classic()) in <boost/algorithm/string/predicate.hpp> (or leave off locale if you want locale-sensitivity). It works with C strings, std::[w]string, vector<char>, etc.

    0 讨论(0)
  • 2020-12-09 03:01

    stricmp is neither POSIX nor ANSI, so it doesn't really matter if strcmp is allowed, if your compiler or standard library is strictly adhering to POSIX or ANSI standard library functions (as is probably the case with the GCC suite).

    0 讨论(0)
提交回复
热议问题